Created
October 11, 2012 19:11
-
-
Save brenttaylor/3874788 to your computer and use it in GitHub Desktop.
This file contains 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
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