Last active
February 13, 2017 03:56
-
-
Save knicklabs/9ad3f496583b73fab2785b510f3fef04 to your computer and use it in GitHub Desktop.
Fun FizzBuzz Solution
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 maybe = (result) => { | |
| return { | |
| if(number) { | |
| return { | |
| divisibleBy(divisor) { | |
| return number % divisor === 0 && result; | |
| } | |
| } | |
| } | |
| } | |
| } | |
| const result = (Array.from({length: 100})).map((_, index) => { | |
| const number = index + 1 | |
| return maybe('FizzBuzz').if(number).divisibleBy(15) | |
| || | |
| maybe('Buzz').if(number).divisibleBy(5) | |
| || | |
| maybe('Fizz').if(number).divisibleBy(3) | |
| || | |
| number | |
| }).join('\n') | |
| console.log(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment