Skip to content

Instantly share code, notes, and snippets.

@Ynote
Last active June 14, 2016 16:47
Show Gist options
  • Save Ynote/042ab3eaf70c21112b03 to your computer and use it in GitHub Desktop.
Save Ynote/042ab3eaf70c21112b03 to your computer and use it in GitHub Desktop.
[Javascript] - Add memoizing and currying function
var add = function() {
add.toString = function() {
console.log(add.total);
};
add.reset = function() {
add.total = 0;
return add;
};
if (!arguments.length) return (add.toString(), add);
add.total = (add.total || 0) + Array.prototype.slice.call(arguments).reduce(function(p, c) { return p + c; });
return add;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment