javascript question to add infinite numbers, without empty parenthesis at the end
I've tried this:
const Sum = function (a) {
function innerFunc (b) {
console.log("B", b)
return b ? Sum(a + b) : a;
}
}
console.log(Sum(2)(3)(4))
but it works for console.log(Sum(2)(3)(4)()) ie an empty parenthesis in the end, is there a way to do it by changing the function so that console log without empty parenthesis gives the correct result, currently it throws an error stating Sum is not a function