Created
March 5, 2019 10:51
-
-
Save supasympa/f6fe83d4d270f3337fc7526fbc8ad675 to your computer and use it in GitHub Desktop.
a simple example of functional programming / chaining
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
const addFive = (v) => (v + 5); | |
const timesTen = (v) => (v * 10); | |
const toObj = (v) => ({value: v}); | |
const addFiveTimesTenObj = (v) => [addFive, timesTen, toObj].reduce((acc, item) => (item(acc)), v); | |
console.log(addFiveTimesTenObj(123)); | |
console.log(addFiveTimesTenObj(13)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment