Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. const double = x => x * 2
  2. const getLength = string => string.length
  3.  
  4. const map = (collection, fn) => collection.map(fn)
  5.  
  6. const messages = ['Hello', 'Bye']
  7.  
  8. const mapToLengths = collection => map(collection, getLength)
  9. const mapToDoubles = collection => map(collection, double)
  10. const pipe = (...fns) => input => fns.reduce((mem, fn) => fn(mem), input)
  11.  
  12. const doubleLengths = pipe(mapToLengths, mapToDoubles)(messages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement