Created
February 5, 2014 17:57
-
-
Save dazld/8829555 to your computer and use it in GitHub Desktop.
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 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