Last active
August 29, 2015 14:13
-
-
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.
This file contains hidden or 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 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