Created
October 17, 2018 10:13
-
-
Save anthonybrown/25ae3a0a270ad0f65fbe61b02be8ecfe to your computer and use it in GitHub Desktop.
An example of a currying in JavaScript
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 currier = function(fn) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
return fn.apply(this, args.concat( | |
Array.prototype.slice.call(arguments, 0))); | |
}; | |
}; |
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 sequence = function(start, end) { | |
var result = []; | |
for (var i = start; i <= end; ++i) { | |
result.push(i); | |
} | |
return result; | |
}; | |
var seq5 = currier(sequence, 1); | |
seq5(5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment