diff --git a/src/fizzbuzz.js b/src/fizzbuzz.js index e3ec3a8..bccabd0 100644 --- a/src/fizzbuzz.js +++ b/src/fizzbuzz.js @@ -1,10 +1,26 @@ -const answer = [] - -// Write your code below this line +/** + * @param {number} num + * @returns {any[]} + */ +function fizzbuzz(num) { + let out = new Array(num) + let iter = '' + for (let i = 1; i <= num; ++i) { + if (i % 3 == 0) iter += 'Fizz' + if (i % 5 == 0) iter += 'Buzz' + if (iter === '') out[i - 1] = i + else { + out[i - 1] = iter + iter = '' + } + } + return out +} +const answer = fizzbuzz(15) // Don't touch the code below this line, we'll cover it later module.exports = answer