Skip to content

Instantly share code, notes, and snippets.

@notmike101
Last active February 8, 2022 21:03
Show Gist options
  • Save notmike101/fa0a38a08146eade655d71bbd5a340d4 to your computer and use it in GitHub Desktop.
Save notmike101/fa0a38a08146eade655d71bbd5a340d4 to your computer and use it in GitHub Desktop.
/*
Print the numbers 1 to 100.
For multiples of 4, print "Fizz".
For multiples of 5 print "Buzz".
For multiples of 8, print "Foo".
For multiples of 10, print "Bar"
For multiples of 4 and 5, print "FizzBuzz".
For multiples of 4 and 8, print "FizzFoo"
For multiples of 4 and 10, print "FizzBar"
For multiples of 5 and 8, print "BuzzFoo"
For multiples of 5 and 10, print "BuzzBar"
For multiples of 8 and 10, print "FooBar"
For multiples of 4, 5, and 8, print "FizzBuzzFoo"
For multiples of 4, 5, and 10, print "FizzBuzzBar"
*/
((start, end, checks = []) => {
for (let number = start; number <= end; number++) {
let output = '';
checks.forEach(([denominator, outString]) => {
if (number % denominator === 0) {
output += outString;
}
});
console.log(output || number);
}
})(1, 100, [[4, 'Fizz'], [5, 'Buzz'], [8, 'Foo'], [10, 'Bar']]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment