Created
May 31, 2017 10:40
-
-
Save getdave/6fe257f0daed2c932736b0dcfdee7bd8 to your computer and use it in GitHub Desktop.
A quick demonstration of the use of a pipe function
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 pipe = (...funcs) => seed => { | |
return funcs.reduce( (acc, func) => { | |
return func(acc); | |
}, seed); | |
} | |
const reverseWord = (val) => { | |
return val.split("").reverse().join(''); | |
}; | |
const convertToUpperCase = (val) => { | |
return val.toUpperCase(); | |
}; | |
const reverseCapitalise = pipe( | |
reverseWord, | |
convertToUpperCase | |
); | |
const result = reverseCapitalise('Hello world'); | |
console.log(result); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment