Skip to content

Instantly share code, notes, and snippets.

@seriousManual
Last active March 25, 2022 11:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seriousManual/dac0b89c336c7d1a3ee1 to your computer and use it in GitHub Desktop.
Save seriousManual/dac0b89c336c7d1a3ee1 to your computer and use it in GitHub Desktop.
Fizzbuzz without a loop in Javascript
Array.from(new Array(30), (value, index) => {
index++
if (index % 5 === 0 || index % 3 === 0) {
if (index % 5 !== 0) return 'Fizz'
if (index % 3 !== 0) return 'Buzz'
return 'FizzBuzz'
}
return index
})
.map(value => console.log(value))
@Danny-Engelman
Copy link

Danny-Engelman commented Mar 25, 2022

Array(30)
  .fill((x, div, label) => x % div ? "" : label)
  .map((func, idx) =>
    func(++idx, 3, "Fizz") + func(idx, 5, "Buzz") || idx
  )
.map(value => console.log(value))

@seriousManual
Copy link
Author

nice, i like it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment