Skip to content

Instantly share code, notes, and snippets.

@alexeykomov
Last active September 5, 2016 15:20
Show Gist options
  • Save alexeykomov/41e7f67497af13c9c46c7513222bb2e3 to your computer and use it in GitHub Desktop.
Save alexeykomov/41e7f67497af13c9c46c7513222bb2e3 to your computer and use it in GitHub Desktop.
function sum(allPreviousSum) {
var newFunction = function(newMember){return sum(allPreviousSum + newMember)}
newFunction.valueOf = function(){return allPreviousSum}
return newFunction;
}
console.log(sum(1) == 1);
console.log(sum(1)(2) == 3);
console.log(sum(1)(2)(3) == 6);
console.log(sum(1)(2)(3)(4) == 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment