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
Here is another functional way using an iterative process
const sum = (num, acc = 0) => { if (!num) return acc; return x => sum(x, acc + num) } sum(1)(2)(3)()
and one-line
const sum = (num, acc = 0) => !num ? acc : x => sum(x, acc + num) sum(1)(2)(3)()