Last active
August 29, 2015 14:02
-
-
Save omas/c6d82bb8afefe50b96e6 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
/* | |
<program> | |
<summary>ケンシロウバージョン</summary> | |
<version>1.0</version> | |
<date>2014/06/19</date> | |
<author>omas</author> | |
<file>fizzbuzz.js</file> | |
<usage>jeek用</usage> | |
</program> | |
*/ | |
var FizzBuzzNumber = function(value) { this.value = value; }; | |
var FizzBuzzChecker = function() { | |
this.conditions = [{'value':3,'message':'あた'} | |
,{'value':5,'message':'あたた'} | |
,{'value':15,'message':'ふぉー'} | |
] | |
]; | |
}; | |
FizzBuzzChecker.prototype.check = function(number){ | |
var prefix = new String(number.value + " -> " ); | |
var message = ""; | |
for (item in this.conditions) | |
if (!(number.value % this.conditions[item].value)) | |
message += this.conditions[item].message; | |
if (!message.length) // 条件に当てはまらない時 | |
message = number.value; | |
return prefix.concat(message); | |
}; | |
function testFizzBuzz() { | |
var MIN = 1; | |
var MAX = 100 + 1; | |
var checker = new FizzBuzzChecker(); | |
for (var i = MIN; i < MAX ; i++) | |
output(checker.check(new FizzBuzzNumber(i))); | |
}; | |
testFizzBuzz(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment