Link to home
Avatar of fadi_fadi
fadi_fadi

asked on

Sum of arg1 and arg2 in JavaScript.

Dear Experts,
Example:

f=makeadder(3)
f(2) /* return 5 */
f(10) /* return 13 */
g=makeadder(-1)
g(2) /* return 1 */
g(10) /* return 9 */
makeadder(5)(6) /* return 11 */


Can you help me to create a function take single input argument and return new function of one argument?

This new function should return the sum of arg1 and arg2 when called.
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

try this
function makeadder( arg1, arg2 )
{
   return function (arg2)
   {
       return (arg1 + arg2);
   }
}
ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of fadi_fadi
fadi_fadi

ASKER

Your are the best.