I am trying to create a function "sum" that adds multiple numbers using an inner function. e.g. sum(1)(2) will print 3 sum(1)(2)(3) will print 6 sum(1)(2)(3)(4) will print 10 and so on
I wrote the following code which works for sum(1)(2).
function sum(num){
function add (b){
console.log(num+=b);
}
return add;
}
How can I extend this to work with multiple calls to inner function?