Skip to content

Instantly share code, notes, and snippets.

@alvieirajr
Created July 13, 2016 13:13
Show Gist options
  • Save alvieirajr/1f36f86d63da3a77e9234e74f43ad44b to your computer and use it in GitHub Desktop.
Save alvieirajr/1f36f86d63da3a77e9234e74f43ad44b to your computer and use it in GitHub Desktop.
// Another Simple example
// Simplest compose
var compose = function(f, g) {
return function(x) {
return f(g(x));
};
};
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;};
console.log(add1(42)); // 43
console.log(square(7)); // 49
var f = compose(add1, square);
console.log(f(7)); // 50
@alvieirajr
Copy link
Author

Drawbacks:

It loses track of the this context used to call it.
It ignores all but the first argument passed to the initial function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment