Skip to content

Instantly share code, notes, and snippets.

@kolja
Created October 26, 2014 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kolja/cb82a12d11ab10228795 to your computer and use it in GitHub Desktop.
Save kolja/cb82a12d11ab10228795 to your computer and use it in GitHub Desktop.
Add Numbers by passing them to the same function in succession
var add = function(x) {
add.sum = add.sum || 0;
add.sum += x;
add.valueOf = function() {
return add.sum;
};
return add;
};
add(1)(2)(3) == 6; // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment