Skip to content

Instantly share code, notes, and snippets.

@taufik-nurrohman
Last active March 27, 2017 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taufik-nurrohman/0c0fcd03cceeafb183d4b6e5865a9d3b to your computer and use it in GitHub Desktop.
Save taufik-nurrohman/0c0fcd03cceeafb183d4b6e5865a9d3b to your computer and use it in GitHub Desktop.
Compose Function
// 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