Created
December 9, 2015 01:57
-
-
Save benatkin/e19dcb0a81e8f767f5bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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