Created
May 10, 2017 15:57
-
-
Save ecancino/4ef98606b358fbacc90ebf998210983c to your computer and use it in GitHub Desktop.
Fizzbuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const range = length => [...Array(length).keys()]; | |
| const divBy = n => v => (v % n === 0) | |
| const divBy3 = divBy(3); | |
| const divBy5 = divBy(5); | |
| const all = (n, xs) => xs.reduce((p, c) => p && c(n), true); | |
| const divBy15 = n => all(n, [ divBy3, divBy5 ]); | |
| const fizbuzz = n => range(n) | |
| .map(n => | |
| divBy15(n) ? `FizzBuzz (${n})` : | |
| divBy3(n) ? `Fizz (${n})` : | |
| divBy5(n) ? `Buzz (${n})` : n); | |
| const fb = fizbuzz(100); | |
| console.log(fb.join(', \n')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment