Skip to content

Instantly share code, notes, and snippets.

@sramam
Last active May 14, 2018 10:42
Show Gist options
  • Save sramam/8ebd2f7f737656f4f4f794a594dd275b to your computer and use it in GitHub Desktop.
Save sramam/8ebd2f7f737656f4f4f794a594dd275b to your computer and use it in GitHub Desktop.
fizzbizz
/**
A fizzbizz implementation in modern JavaScript
*/
const fizzbizz = (n) => {
const fz = (n) => {
switch(true) {
case (n%15 === 0): return 'fizzbizz';
case (n%5 === 0): return 'bizz';
case (n%3 === 0): return 'fizz';
default: return `${n}`;
}
}
console.log(`${n}: ${fz(n)}`);
}
[...Array(100)].forEach((el, idx) => fizzbizz(idx));
// (new Array(100)).map((el, idx) => fizzbizz(idx));
// for(let n=0; n<=100; n++) {
// fizzbizz(n)
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment