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
To make sum(1) callable as sum(1)(2), it must return a function.
sum(1)
sum(1)(2)
The function can be either called or converted to a number with valueOf.
valueOf
function sum(a) { var sum = a; function f(b) { sum += b; return f; } f.toString = function() { return sum } return f }