Created
May 9, 2020 09:49
-
-
Save AlexanderGW/386c97e2b2dc0cce5dc05995f36daff5 to your computer and use it in GitHub Desktop.
FizzBuzz in JS and PHP, using nested ternaries.
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
// Vanilla | |
for (var i = 1; i <= 100; i++) { | |
console.log | |
((i % 15 === 0) ? 'FizzBuzz' : | |
((i % 5 === 0) ? 'Buzz' : | |
((i % 3 === 0) ? 'Fizz' : | |
i | |
) | |
) | |
); | |
} | |
// ES15+ | |
for (let i = 1; i <= 100; i++) { | |
console.log | |
((i % 15 === 0) ? 'FizzBuzz' : | |
((i % 5 === 0) ? 'Buzz' : | |
((i % 3 === 0) ? 'Fizz' : | |
i | |
) | |
) | |
); | |
} |
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
<?php | |
for ($i = 1; $i <= 100; $i++) { | |
echo | |
(($i % 15 == 0) ? 'FizzBuzz' : | |
(($i % 5 == 0) ? 'Buzz' : | |
(($i % 3 == 0) ? 'Fizz' : | |
$i | |
) | |
) | |
) . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment