Created
September 19, 2018 22:52
-
-
Save jordanhudgens/3f0fb6578caa794226a472f3a125a787 to your computer and use it in GitHub Desktop.
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 functionalFizzBuzz = n => { | |
return Array.from( | |
{ length: n }, | |
(_, idx) => | |
[[15, "fizzbuzz"], [5, "buzz"], [3, "fizz"]].find( | |
val => (idx + 1) % val[0] === 0 | |
) || idx + 1 | |
).reduce((acc, el) => (acc += (el[1] || el) + "\n"), ""); | |
}; | |
functionalFizzBuzz(15); | |
// "1 2 fizz 4 buzz fizz 7 8 fizz buzz 11 fizz 13 14 fizzbuzz" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment