Skip to content

Instantly share code, notes, and snippets.

@alexeykomov
Last active February 14, 2018 12:01
Show Gist options
  • Save alexeykomov/7ce0d67813e602e5a4d45adcba28f508 to your computer and use it in GitHub Desktop.
Save alexeykomov/7ce0d67813e602e5a4d45adcba28f508 to your computer and use it in GitHub Desktop.
function sum(firstArg, opt_argsStack) {
const argsStack = (opt_argsStack || []).concat([firstArg]);
const nextSum = nextArg => sum(nextArg, argsStack);
nextSum.valueOf = () => argsStack.reduce((a, b) => a + b);
return nextSum;
}
console.log(+sum(1));
console.log(+sum(1)(2));
console.log(+sum(1)(2)(3));
console.log(+sum(1)(2)(3)(4));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment