Skip to content

Instantly share code, notes, and snippets.

@anthonybrown
Created October 17, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anthonybrown/25ae3a0a270ad0f65fbe61b02be8ecfe to your computer and use it in GitHub Desktop.
Save anthonybrown/25ae3a0a270ad0f65fbe61b02be8ecfe to your computer and use it in GitHub Desktop.
An example of a currying in JavaScript
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)));
};
};
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