I'm learning JavaScript, and I recently came across a practice problem that asked me to construct a function that could create outputs as follows:
var threeSum= sum(3);
threeSum //3
threeSum(4) //7
threeSum(4)(3) //10
threeSum(4)(3)(7) //17
threeSum(4)(3)(7)()(2) //19
threeSum - 2 //1
threeSum + 2 //5
I assume currying is involved, and I think I have a basic grasp of how currying works in the simple form of something like
a=>b=>c=> a+b+c
but I have no notion of how I would create a curried function able to handle an indeterminate number of inputs, nor how to make it such that it could result in a variable that can act as both a value and a function.
Any insight is appreciated! I just need a push in the right direction -- at this point I don't even know what I'm looking for anymore.