Last active
July 13, 2016 13:17
-
-
Save alvieirajr/6603fe49de38a140b1e7721f9b24840c 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
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