Skip to content

Instantly share code, notes, and snippets.

@chrisslater
Last active August 29, 2015 14:01
Show Gist options
  • Save chrisslater/11559013 to your computer and use it in GitHub Desktop.
Save chrisslater/11559013 to your computer and use it in GitHub Desktop.
// Some doc
// Walkthrough https://medium.com/the-javascript-collection/ce6da2d324fe
// 'arguments' native variable: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions_and_function_scope/arguments
var curry = function(fn){
var args = Array.prototype.slice.call(arguments, 1);
return function(){
return fn.apply(this, args.concat(
Array.prototype.slice.call(arguments, 0)));
};
};
// Create test function
var sequence = function(start, end){
var result = [];
for(var i = start; i <= end; i++){
result.push(i);
}
return result;
};
var seq = curry(sequence, 1);
seq(5); // [1,2,3,4,5];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment