I have a problem with suming up an infinite number of arguments in brackets for function sum(). I make a function that can sum two brackets with arguments for sum function, but I do not understand how can I sum a various count of brackets...
I would be grateful for the answer.
function sum(a) {
return function(b) {
return a + b; //
};
}
console.log(sum(1)(2)); // 1 + 2
console.log(sum(1)(2)(3)); // 1 + 2 + 3
console.log(sum(5)(-1)(2));
console.log(sum(6)(-1)(-2)(-3));
console.log(sum(0)(1)(2)(3)(4)(5));