Skip to content

Instantly share code, notes, and snippets.

@dazld
Created February 5, 2014 17:57
Show Gist options
  • Save dazld/8829555 to your computer and use it in GitHub Desktop.
Save dazld/8829555 to your computer and use it in GitHub Desktop.
var partialRight = function(fn){
var args = [].slice.call(arguments);
var partiallyFilledArguments = args.length > 1 ? args.slice(1, args.length) : [];
return function(){
var remainingArgs = [].slice.call(arguments);
return fn.apply(null, remainingArgs.concat(partiallyFilledArguments));
}
}
function add(){
var vals = [].slice.call(arguments);
return vals.reduce(function(curr, val){
return curr+val;
},0);
}
var add2 = partialRight(add, 1,2,3);
var add3 = partialRight(add2, 4,5,6)
console.log(add3(7)); // 28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment