Created
October 10, 2015 16:16
-
-
Save ccnixon/ff315521c1cb95aa3f9f to your computer and use it in GitHub Desktop.
Compose and Pipe
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 compose = function(){ | |
//Your code here | |
var args = Array.prototype.slice.call(arguments); | |
return function(val){ | |
return args.reduceRight(function(memo, fn){ | |
return fn(memo); | |
}, val); | |
}; | |
}; | |
var pipe = function(){ | |
//Your code here | |
var args = Array.prototype.slice.call(arguments); | |
return function(val){ | |
return args.reduce(function(memo, fn){ | |
return fn(memo); | |
}, val); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick reproduction of native compose and pipe in JS