Created
April 11, 2018 23:48
-
-
Save sethdavis512/d83805e49486806e8ac5579e1cd36c91 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
const scream = str => str.toUpperCase() | |
const exclaim = str => `${str}!` | |
const repeat = str => `${str} ${str}` | |
const string = 'Egghead.io is awesome' | |
// Nested | |
const result2 = repeat(exclaim(scream(string))) | |
// EGGHEAD.IO IS AWESOME! EGGHEAD.IO IS AWESOME! | |
const compose = (...fns) => x => | |
fns.reduceRight((acc, fn) => fn(acc), x) | |
// Instead of nesting, compose your functions into a new function | |
const enhance = compose(repeat, exclaim, scream) | |
console.log(enhance(string)) | |
// EGGHEAD.IO IS AWESOME! EGGHEAD.IO IS AWESOME! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment