Skip to content

Instantly share code, notes, and snippets.

@Zyber17
Last active August 2, 2017 02:18
Show Gist options
  • Save Zyber17/52dafa9bc3c6f6ebd73ec5e6c453d729 to your computer and use it in GitHub Desktop.
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.
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