Skip to content

Instantly share code, notes, and snippets.

@JO3-W3B-D3V
Created September 24, 2019 17:12
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 JO3-W3B-D3V/f6585df50e06c2f55449edad26f47b32 to your computer and use it in GitHub Desktop.
Save JO3-W3B-D3V/f6585df50e06c2f55449edad26f47b32 to your computer and use it in GitHub Desktop.
This is a concise fizzbuzz solution.
/**
* This is just an example of how concise the FizzBuzz solution can be.
* This may not be the most efficient or elegant solution in the world, but eh, it's a bit of fun! :)
*/
// Just off load the logic to a method for the sake of ease.
// It could be a one line solution, but it's a little harder to read that way.
const print = i => (i % 3 == 0 ? 'Fizz' : '') + (i % 5 == 0 ? 'Buzz' : '') || i;
// Now to iterate over an array with 100 elments & print the solution.
Array.from(Array(100).keys()).map(i => ++i).forEach(i => console.log(print(i)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment