Skip to content

Instantly share code, notes, and snippets.

@benatkin
Created December 9, 2015 01:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save benatkin/e19dcb0a81e8f767f5bb to your computer and use it in GitHub Desktop.
class Buzzer {
constructor(message, factor) {
this.factor = factor;
this.message = message;
}
buzz(number) {
if (number % this.factor == 0) {
console.log(this.message);
return true;
}
}
}
class Fizzer {
constructor(buzzers, min, max) {
this.buzzers = buzzers;
this.min = min;
this.max = max;
}
fizz() {
for (var i=this.min; i <= this.max; i++) {
this.fizzNumber(i);
}
}
fizzNumber(number) {
const buzzed = this.buzzers.some((buzzer) => {
return buzzer.buzz(number);
});
if (!buzzed) console.log(number);
}
}
var fizzBuzz = new Fizzer(
[
new Buzzer('FizzBuzz', 15),
new Buzzer('Fizz', 3),
new Buzzer('Buzz', 5)
], 1, 100
);
fizzBuzz.fizz();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment