# Function multiply(a, b){ a * b }

119 views

## 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:

``````multiplyfunc(a,b){

return a*b;

}``````

They want me to do a math with below approach

``multiplyfunc(a)(b)``

Is it possible to do it?

## 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;
console.log(multiplyfunc(4)(3));``````

OR

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

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

console.log(multiplyfunc(4)(3));``````

OR

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)

Example:

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
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?
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?
1 vote