Last active
March 27, 2017 04:17
-
-
Save taufik-nurrohman/0c0fcd03cceeafb183d4b6e5865a9d3b to your computer and use it in GitHub Desktop.
Compose Function
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
// Reply for <https://medium.com/@Dewey92/cleaner-code-dengan-function-composition-137f30d928e4> | |
function compose() { | |
var i, arg = arguments, | |
output = arg.pop(); | |
for (i = 0; i < arg.length; ++i) { | |
if (typeof arg[i] !== "function") continue; | |
output = arg[i](output); | |
} | |
return output; | |
} | |
function fn1(x) {} | |
function fn2(x) {} | |
function fn3(x) {} | |
console.log(compose(fn1, fn2, fn3, 77)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment