Junior — Senior
Addition function with support for partial call
livecode
Task condition
Implement a function that accumulates arguments through successive calls and returns their total value when called without parameters. The function should work as a chain of calls, where each call takes one argument and returns a new function of the same type, and the final call without arguments returns the accumulated sum.
const partialSum = () => {};
// console.log(partialSum()); // → 0
// console.log(partialSum(1)()); // → 1
// console.log(partialSum(2)(3)()); // → 5
// console.log(partialSum(10)(7)(41)()); // → 58