Skip to content

Instantly share code, notes, and snippets.

@tovic tovic/compose-function.js
Last active Mar 27, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.