Last active
August 2, 2017 02:18
-
-
Save Zyber17/52dafa9bc3c6f6ebd73ec5e6c453d729 to your computer and use it in GitHub Desktop.
A Javascript fizzbuzz which is entirely functional and does not contain any of the following as substrings: for, while, if, else, return.
This file contains 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 fbGen = (fbValues, min, max) => | |
Array.apply(null, Array(max - min + 1)) | |
.map((val, i) => min + i) | |
.map(val => | |
fbValues.reduce( | |
(accum, fbVal) => | |
val % fbVal.number === 0 ? `${accum}${fbVal.text}` : accum, | |
'' | |
) || val | |
) | |
.join('\n') | |
const fizzbuzz = fbGen( | |
[{ number: 3, text: 'Fizz' }, { number: 5, text: 'Buzz' }], | |
0, | |
100 | |
) | |
console.log(fizzbuzz) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment