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