Skip to content

Instantly share code, notes, and snippets.

@sethdavis512
Created April 11, 2018 23:48
Show Gist options
  • Save sethdavis512/d83805e49486806e8ac5579e1cd36c91 to your computer and use it in GitHub Desktop.
Save sethdavis512/d83805e49486806e8ac5579e1cd36c91 to your computer and use it in GitHub Desktop.
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