Created
May 17, 2016 01:18
-
-
Save andredublin/b37804fe46780bb6ee3d8734a3ed77f7 to your computer and use it in GitHub Desktop.
composition and map
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
// composition = f(g(x)) | |
var compose = function(f, g) { | |
return function(x) { | |
return f(g(x)); | |
} | |
} | |
var squareAdd10 = compose(square, add10); | |
[1, 2, 3, 4, 5].map(squareAdd10); // 11, 14, 19, 26, 35 | |
// or | |
var squared = [1, 2, 3, 4, 5].map(square); // 1, 4, 9, 16, 25 | |
var added = [1, 2, 3, 4, 5].map(add10); // 11, 14, 19, 26, 35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment