Last active
December 30, 2015 08:19
-
-
Save fonzerelly/7801729 to your computer and use it in GitHub Desktop.
solution: a closure, that cuts of all surplus parameters
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
_.mixin( | |
{ | |
"preserveCallersFirstNParams" : function (func, n) { | |
n = n || 0; | |
return function () { | |
return func.apply(this, Array.prototype.slice.call(arguments, 0, n)); | |
}; | |
} | |
); | |
var getNumberOfPages = _.preserveCallersFirstNParams( | |
_.partialRight( | |
_.result, | |
"numberOfPages" | |
), | |
1 | |
); | |
_.map(books, getNumberOfPages); | |
//32, 36, 32 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment