Created
April 16, 2021 01:58
-
-
Save gngenius02/9dbcdb36a772fa35d787b373ee116248 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 short and quick method. | |
*/ | |
const fizzbuzz = (int) => !(int % 15) ? "FizzBuzz" : !(int % 5) ? "Buzz" : !(int % 3) ? "Fizz" : int; | |
let i = 1; | |
console.log(new Array(100).fill().map(_ => fizzbuzz(i++))) | |
/** | |
* FizzBuzz longer but versatile method. | |
*/ | |
const getFizzBuzz = (testCases, j) => { | |
const outArray = []; | |
for (let i = 1; i <= j; i++){ | |
output = ''; | |
for (let key in testCases){ | |
if (!(i%key)){ | |
output += testCases[key] | |
} | |
} | |
if (output == '') | |
output = i; | |
outArray.push(output); | |
} | |
return outArray; | |
} | |
const testCases = {3: "Fizz", 5: "Buzz", 6: "HAHA"} | |
console.log(getFizzBuzz(testCases, 100)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment