• Register
0 votes

Problem :

I have the very unique question from the programming background. They want me to write the function which should multiply (a) and (b) but not writing it like below one:


return a*b;


They want me to do a math with below approach


Is it possible to do it?

7.5k points

1 Answer

0 votes

Solution :

I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the problem with the people getting started..

You should make the function that returns another function as shown below.

const multiplfunc = a => b => a * b;



Try with the function that returns the function as shown below :

function multiplyfunc (a) {
  return function (b) {
    return a * b;




Currying is the process used to reduce the functions of more than one argument to the functions of one argument with the help of the lambda calculus.

f(n, m) --> f'(n)(m)


multiplyfunc = (n, m) => (n * m)

multiplyfunc(3, 4) === 12 // true

curryedMultiplyfunc = (n) => ( (m) => multiplyfunc(n, m) )

triplefunc = curryedMultiplyfunc(3)

triplefunc(4) === 12 // true


I hope it helps you in solving your issue.

36.1k points

Related questions

1 vote
2 answers 580 views
Problem: I recently started learning python programming. This is my very first attempt to write a code run the program. I tried to compile my program but it throwing me back an error. def multiply(a, b): a * b What should I do now?
asked Mar 9 Gavin 15.2k points
0 votes
2 answers 58 views
Problem: I am new to programming, so need query to get query to return max number from 3 integer? Write the definition of a method max that has three int parameters and returns the largest? Can anyone guide with correct code?
asked Feb 17 maddi86 5.4k points
1 vote
1 answer 40 views
Problem : I am very new to Vanilla JavaScript. Currently I am learning Vanilla JavaScript as I need to use the Vanilla JavaScript for my current project. I have already written many functions one of them has a button in it which should open the menu and it only ... spent a lot of time in fixing target id issue so looking for Vanilla JavaScript experts help who can suggest quick fix on above error.
asked Apr 23 stewart 4k points
0 votes
1 answer 3 views
I have a function that I want to take, as a parameter, a variable size 2D array. So far I have this: void myFunction (double ** myArray) { myArray [x] [y] = 5; etc... } And I have showed an array in my code: double anArray [10] [10]; However, ... changes made to my Function should alter the state of an Array. If I understand correctly, I just want to pass as argument a pointer to a 2D array.
asked 18 hours ago game 980 points
0 votes
1 answer 11 views
Problem: Hello guys, I was learning the function in python, and wondering can we use function within a function then I google some stuff then got to know that function within the function is better way of implementing the algorithm we are implementing, can you guys please show it with an example.
asked Jun 5 Gavin 15.2k points