Skip to content

Instantly share code, notes, and snippets.

@plugn
Last active March 29, 2020 00:18
Show Gist options
  • Save plugn/ba700dd34fc8d633c77ef218bdd0fe77 to your computer and use it in GitHub Desktop.
Save plugn/ba700dd34fc8d633c77ef218bdd0fe77 to your computer and use it in GitHub Desktop.
const range = (min, max) => Array.from(Array(max - min + 1).keys()).map(v => v + min)
const fizzBuzz = (max, min = 1) =>
range(min, max)
.reduce((acc, num) =>
[...acc, ((num % 3 ? '' : 'Fizz') + (num % 5 ? '' : 'Buzz') || num)],
[])
.join(', ')
// fizzBuzz(18)
// 1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment