Created
July 13, 2016 13:13
-
-
Save alvieirajr/1f36f86d63da3a77e9234e74f43ad44b to your computer and use it in GitHub Desktop.
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
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Drawbacks:
It loses track of the this context used to call it.
It ignores all but the first argument passed to the initial function.