Created
August 9, 2023 16:49
-
-
Save suhailgupta03/b6fa54be8dd583ed217b32ec466ada65 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Input 5 | |
// output 11 | |
// (5 + 5) + 1 | |
function multiply(n){ | |
return 2 * n | |
} | |
function add(n) { | |
return n + 1 | |
} | |
function compose(x, y) { | |
// x = add | |
// y = multiply | |
return function(n) { | |
// y(n) = 10 | |
return x(y(n)) | |
} | |
} | |
let multiplyAndAdd = compose(add, multiply) | |
var result = multiplyAndAdd(5) | |
console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another simple example: https://gist.github.com/suhailgupta03/896b1b92a6ad3dfa1530dc7349276ea5