Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. // Fizzbuzz using functional style
  2. const divisibleBy = x => n => n % x == 0,
  3. divisibleByFifteen = divisibleBy(15),
  4. divisibleByThree = divisibleBy(3),
  5. divisibleByFive = divisibleBy(5),
  6.  
  7. takeFrom = number => start => Array(number).fill().map((e,i) => i + start),
  8. oneToOneHundredMap = func => takeFrom(100)(1).map(func),
  9.  
  10. ifTrue = cond => str => n => cond(n) && str || n,
  11.  
  12. fizz = ifTrue(divisibleByThree)('fizz'),
  13. buzz = ifTrue(divisibleByFive)('buzz'),
  14. fizzBuzz = ifTrue(divisibleByFifteen)('fizzbuzz'),
  15.  
  16. applyFizzBuzz = n => fizz(buzz(fizzBuzz(n)))
  17.  
  18.  
  19. console.log(oneToOneHundredMap(applyFizzBuzz))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement