Last active
April 12, 2016 13:42
-
-
Save mjgpy3/afec10d879923fd6df580bca1df78951 to your computer and use it in GitHub Desktop.
Function composition in JavaScript
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
function compose() { | |
return Array | |
.prototype | |
.slice | |
.call(arguments) | |
.reduce(compose2, identity); | |
} | |
function compose2(f, g) { | |
return function (x) { | |
return f(g(x)); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment