Guest User

Untitled

a guest
Jun 18th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. 1 const scream = str => str.toUpperCase()
  2. 2 const exclaim = str => `${str}!`
  3. 3 const repeat = str => `${str} ${str}`
  4. 4
  5. 5 const string = 'Hello world'
  6. 6
  7. 7 // Nested
  8. 8 // const result1= repeat(exclaim(scream(string)))
  9. 9 // console.log(result1)
  10. 10 // HELLO WORLD! HELLO WORLD!
  11. 11
  12. 12 // Instead of nesting, compose your functions into a new function
  13. 13 const compose = (...fns) => x =>
  14. 14 fns.reduceRight((acc, fn) => fn(acc), x)
  15. 15
  16. 16 const enhance = compose(repeat, exclaim, scream)
  17. 17 const result2 = enhance(string)
  18. 18 console.log(result2)
  19. 19 // HELLO WORLD! HELLO WORLD!
Add Comment
Please, Sign In to add comment