Skip to content

Instantly share code, notes, and snippets.

@nubunto
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save nubunto/482bfba61597bc650d0b to your computer and use it in GitHub Desktop.

Select an option

Save nubunto/482bfba61597bc650d0b to your computer and use it in GitHub Desktop.
A implementation of the "compose" function that takes a arbitrary number of functions.
var compose = function () {
//take the functions passed in as an array.
var fns = [].slice.call(arguments, 0);
//returns a function that will combine all of them
return function (arg) {
return fns.reduce(function (retValue, next) {
return next.call(null, retValue);
}, arg); //the initial value will be the argument
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment