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 a solution that uses ES6 and toString, similar to @Vemba
toString
function add(a) { let curry = (b) => { a += b return curry } curry.toString = () => a return curry } console.log(add(1)) console.log(add(1)(2)) console.log(add(1)(2)(3)) console.log(add(1)(2)(3)(4))