While doing some JavaScript challenges, I faced with the code add(1)(2), a function being called with several parenthesis. The challenge is to make a chain of add function.
add(1)(2)(3); // -> 6
add(1)(2)(3)(4); // -> 10
add(1)(2)(3)(4)(5); // -> 15
Also, we should be able to store the returned values and reuse them.
var addTwo = add(2);
addTwo; // -> 2
addTwo + 5; // -> 7
addTwo(3); // -> 5
addTwo(3)(5); // -> 10
Thanks in advance.