Created
October 26, 2014 12:44
-
-
Save kolja/cb82a12d11ab10228795 to your computer and use it in GitHub Desktop.
Add Numbers by passing them to the same function in succession
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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