Created
January 20, 2016 13:55
-
-
Save ChillyBwoy/9973d9eac3d165099f84 to your computer and use it in GitHub Desktop.
FizzBuzz
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
// with array. More more more faster | |
Array.apply(null, Array(100)).map((_, i) => { | |
var n = i + 1; | |
return (n % 3 === 0 && n % 5 === 0 ? 'FizzBuzz' : | |
(n % 3 === 0 ? 'Fizz' : | |
(n % 5 === 0 ? 'Buzz' : n))) | |
}); | |
// with recursion | |
const fizzBuzz = (size, acc = []) => { | |
if (size <= 0) { | |
return acc; | |
} | |
let n = acc.length + 1; | |
let word = (n % 3 === 0 && n % 5 === 0 ? 'FizzBuzz' : | |
(n % 3 === 0 ? 'Fizz' : | |
(n % 5 === 0 ? 'Buzz' : n))); | |
return fizzBuzz(size - 1, [...acc, word]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment