Skip to content

Instantly share code, notes, and snippets.

@fdjones
Created August 8, 2017 22:25
Show Gist options
  • Save fdjones/725f6fa5a6ec112bfd6171e2de7f4cec to your computer and use it in GitHub Desktop.
Save fdjones/725f6fa5a6ec112bfd6171e2de7f4cec to your computer and use it in GitHub Desktop.
function isDivisibleByY(n, y) {
return n % y === 0; // returns true or false
}
function createNewArray(n) {
return Array.from(Array(n).keys()).map(i => ++i)
}
function print(string) {
console.log(string);
}
createNewArray(100).forEach(function(elem) {
console.log(elem);
if(isDivisibleByY(elem, 3) && isDivisibleByY(elem, 5)) {
print('Fizz Buzz');
}
else if(isDivisibleByY(elem, 3)) {
print('Fizz');
}
else if(isDivisibleByY(elem, 5)) {
print('Buzz');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment