Skip to content

Instantly share code, notes, and snippets.

@basekays
Created June 19, 2018 18:25
Show Gist options
  • Select an option

  • Save basekays/d2cc3ab9419d227c87e0f4851ee40526 to your computer and use it in GitHub Desktop.

Select an option

Save basekays/d2cc3ab9419d227c87e0f4851ee40526 to your computer and use it in GitHub Desktop.
//input = number
//output = array of string
//test case
//5
// -> ['1', '2', 'Fizz', '4', 'Buzz'];
function fizzBuzz(number) {
var result = [];
for (var i = 1; i <= number; i++) {
if (i%3 == 0 && i%5 == 0) {
result.push('FizzBuzz');
} else if (i%3 == 0) {
result.push('Fizz');
} else if (i%5 == 0) {
result.push('Buzz');
} else {
result.push(i.toString());
}
}
return result;
}
fizzBuzz(20);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment