Skip to content

Instantly share code, notes, and snippets.

@brenttaylor
Created October 11, 2012 19:11
Show Gist options
  • Save brenttaylor/3874788 to your computer and use it in GitHub Desktop.
Save brenttaylor/3874788 to your computer and use it in GitHub Desktop.
function FizzBuzz() {
this.TestCases = new Array();
this.AddCase = function(Name, DivisibleBy) {
this.TestCases.push(
function (x) {
return x % DivisibleBy === 0 ? Name : '';
}
);
};
this.Run = function(x) {
for (var i = 0; i <= x; i++) {
var Output = '';
for (var Case = 0; Case < this.TestCases.length; Case++) {
Output += this.TestCases[Case](i);
}
console.log(Output === '' ? i : Output);
}
};
}
var fb = new FizzBuzz();
fb.AddCase("Fizz", 3);
fb.AddCase("Buzz", 5);
fb.Run(15);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment