Created
December 12, 2020 01:47
-
-
Save moonformeli/4d30a98e60d378e64763b548864d92a4 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
function add5(x) { | |
return x + 5; | |
} | |
function mul10(x) { | |
return x * 10; | |
} | |
function pipe(...fn) { | |
return function(v) { | |
return fn.reduce(function(_v, _fn) { | |
return _fn(_v); | |
}, v); | |
} | |
} | |
pipe( | |
add5, | |
mul10, | |
add5 | |
)(5); | |
// The result is 105 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment