Last active
September 6, 2019 12:09
-
-
Save paulhhowells/50f62248a6da686992ca72020128f7a3 to your computer and use it in GitHub Desktop.
This file contains 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
// FizzBuzz | |
// Terseness vs Readability | |
function fizzBuzz (value) { | |
let output = ''; | |
if (value % 3 === 0) { | |
output += 'Fizz'; | |
} | |
if (value % 5 === 0) { | |
output += 'Buzz'; | |
} | |
return output || value; | |
} | |
function fizzBuzz (value) { | |
const fizz = (value % 3 === 0); | |
const buzz = (value % 5 === 0); | |
let output = ''; | |
if (fizz) { | |
output += 'Fizz'; | |
} | |
if (buzz) { | |
output += 'Buzz'; | |
} | |
return output || value; | |
} | |
function fizzBuzz (value) { | |
const fizz = (value % 3 === 0); | |
const buzz = (value % 5 === 0); | |
let output = ''; | |
output += fizz ? 'Fizz' : ''; | |
output += buzz ? 'Buzz' : ''; | |
return output || value; | |
} | |
function fizzBuzz (value) { | |
let output = ''; | |
output += (value % 3 === 0) ? 'Fizz' : ''; | |
output += (value % 5 === 0) ? 'Buzz' : ''; | |
return output || value; | |
} | |
function fizzBuzz (value) { | |
const fizz = (value % 3 === 0) ? 'Fizz' : ''; | |
const buzz = (value % 5 === 0) ? 'Buzz' : ''; | |
return fizz + buzz || value; | |
} | |
function fizzBuzz (value) { | |
return (value % 15 === 0) | |
? 'FizzBuzz' | |
: (value % 3 === 0) | |
? 'Fizz' | |
: (value % 5 === 0) | |
? 'Buzz' | |
: value; | |
} | |
function fizzBuzz (value) { | |
switch (0) { | |
case (value % 15): return 'FizzBuzz'; | |
case (value % 3): return 'Fizz'; | |
case (value % 5): return 'Buzz'; | |
} | |
return value; | |
} | |
for (var i = 1; i <= 100; i++) { | |
console.log( fizzBuzz(i) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment