Last active
January 23, 2019 10:04
-
-
Save cpave3/e2213dfea0e4b752305272608aca2c4d to your computer and use it in GitHub Desktop.
Nodejs Fizzbuzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// The normal way | |
for(let i = 1; i <= 100; i++) { | |
let fizzable = false, buzzable = false; | |
fizzable = (i % 3 === 0) ? true : false; | |
buzzable = (i % 5 === 0) ? true : false; | |
fizzable && buzzable ? console.log('Fizzbuzz') : fizzable ? console.log('Fizz') : buzzable ? console.log('Buzz') : console.log(i); | |
} | |
// Single Line | |
for(let i = 1; i <= 100; i++) i % 3 === 0 && i % 5 === 0 ? console.log('Fizzbuzz') : i % 3 === 0 ? console.log('Fizz') : i % 5 === 0 ? console.log('Buzz') : console.log(i); | |
// A better way? | |
let l=console.log,f='fizz',b='buzz',i; | |
for(i=1;i<100;++i)i%3||i%5?i%3?i%5?l(i):l(b):l(f):l(f+b); | |
// Oooh | |
for(let i=0;i<100;console.log(((++i%3?'':'fizz')+(i%5?'':'buzz'))||i)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment