Skip to content

Instantly share code, notes, and snippets.

@anatoliyarkhipov
Created June 13, 2014 13:27
Show Gist options
  • Save anatoliyarkhipov/2208594b57319042856d to your computer and use it in GitHub Desktop.
Save anatoliyarkhipov/2208594b57319042856d to your computer and use it in GitHub Desktop.
function sum(args){
return Array.prototype.reduce.call(args, function(a, b){ return a + b }, 0)
}
function add(){
var total = sum(arguments),
self = function(){ total += sum(arguments); return self }
return (self.valueOf = function(){ return total }, self)
}
console.log(add(1, 2, 3, 4));
console.log(add(5)(6)(7)(8));
console.log(add(1, 3)(5, 7));
console.log(add(2, 4, 6)(8));
console.log(add(1)(2, 1, 2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment