I need a js sum function to work like this:
sum(1)(2) = 3 sum(1)(2)(3) = 6 sum(1)(2)(3)(4) = 10 etc.
I heard it can\'t be done. But heard
New ES6 way and is concise.
You have to pass empty () at the end when you want to terminate the call and get the final value.
const sum= x => y => (y !== undefined) ? sum(x + y) : x;
call it like this -
sum(10)(30)(45)();