Skip to content

Instantly share code, notes, and snippets.

@alvieirajr
Last active July 13, 2016 13:17
Show Gist options
  • Save alvieirajr/6603fe49de38a140b1e7721f9b24840c to your computer and use it in GitHub Desktop.
Save alvieirajr/6603fe49de38a140b1e7721f9b24840c to your computer and use it in GitHub Desktop.
var compose = function() {
var funcs = arguments;
return function() {
var args = arguments;
for (var i = funcs.length; i --> 0;) {
args = [funcs[i].apply(this, args)];
}
return args[0];
};
};
var add1 = function(x) {return x + 1;};
var mult2 = function(x) {return x * 2;};
var square = function(x) {return x * x;};
var negate = function(x) {return -x;};
var f = compose(negate, square, mult2, add1);
console.log(f(2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment