-
-
Save monsat/5343261 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
function Animal(data) { | |
this.data = data; | |
this.base = '1966/12/31'; | |
this.count = data.length; | |
} | |
Animal.prototype.get = function(birthday) { | |
var number = this.number(birthday); | |
var data = this.data[number]; | |
data.number = number; | |
return data; | |
} | |
Animal.prototype.number = function(birthday) { | |
var date = this.strtotime(birthday); | |
var base = this.strtotime(this.base); | |
var result = (date - base + 1) % this.count; | |
if (result < 0) { | |
result += this.count; | |
} | |
return result; | |
} | |
Animal.prototype.strtotime = function(date) { | |
var HOUR = 1000 * 60 * 60; | |
var date = Date.parse(date); | |
date += HOUR * 9; | |
date /= (HOUR * 24); | |
return date; | |
} |
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
var animals = [ | |
{animal: "トラ", type: "心優しいトラ"}, | |
{animal: "チーター", type: "おしゃれな チーター"}, | |
{animal: "たぬき", type: "飾り気のないたぬき"}, | |
{animal: "さる", type: "センスのあるさる"}, | |
{animal: "コアラ", type: "意志が強く努力家のコアラ"}, | |
{animal: "ひょう", type: "人気者の黒ひょう"}, | |
{animal: "トラ", type: "愛情いっぱいのトラ"}, | |
{animal: "チーター", type: "上品なチーター"}, | |
{animal: "たぬき", type: "人をサポートするたぬき"}, | |
{animal: "さる", type: "大きな志を持ったさる"}, | |
{animal: "コアラ", type: "感激屋のコアラ"}, | |
{animal: "こじか", type: "純真なこじか"}, | |
{animal: "ゾウ", type: "直感型のゾウ"}, | |
{animal: "おおかみ", type: "正義感の強いおおかみ"}, | |
{animal: "ひつじ", type: "情熱的なひつじ"}, | |
{animal: "さる", type: "発展していくさる"}, | |
{animal: "コアラ", type: "繊細な心を持つコアラ"}, | |
{animal: "こじか", type: "強い意志を持ったこじか"}, | |
{animal: "ゾウ", type: "まっしぐらに突き進むゾウ"}, | |
{animal: "おおかみ", type: "お人好しのおおかみ"}, | |
{animal: "ひつじ", type: "慈悲ぶかいひつじ"}, | |
{animal: "ペガサス", type: "どこまでも熱いペガサス"}, | |
{animal: "ペガサス", type: "おおらかな精神を持つペガサス"}, | |
{animal: "ひつじ", type: "陽気なひつじ"}, | |
{animal: "おおかみ", type: "几帳面なおおかみ"}, | |
{animal: "おおかみ", type: "探求心のあるおおかみ"}, | |
{animal: "ひつじ", type: "人の力を 育むひつじ"}, | |
{animal: "ペガサス", type: "芸術家であるペガサス"}, | |
{animal: "ペガサス", type: "自分に正直なペガサス"}, | |
{animal: "ひつじ", type: "チャレンジ精神旺盛なひつじ"}, | |
{animal: "おおかみ", type: "粘り強いおおかみ"}, | |
{animal: "ゾウ", type: "リーダーとなるゾウ"}, | |
{animal: "こじか", type: "正義感の強いこじか"}, | |
{animal: "コアラ", type: "個性豊かなコアラ"}, | |
{animal: "さる", type: "フランクなさる"}, | |
{animal: "ひつじ", type: "面倒見の良いひつじ"}, | |
{animal: "おおかみ", type: "分析力に優れたおおかみ"}, | |
{animal: "ゾウ", type: "度量の大きいゾウ"}, | |
{animal: "こじか", type: "人懐っこいこじか"}, | |
{animal: "コアラ", type: "感受性の強いコアラ"}, | |
{animal: "さる", type: "頭脳明晰なさる"}, | |
{animal: "たぬき", type: "控えめなたぬき"}, | |
{animal: "チーター", type: "俊敏なチーター"}, | |
{animal: "トラ", type: "アクティブなトラ"}, | |
{animal: "ひょう", type: "ユーモアにあふれた黒ひょう"}, | |
{animal: "コアラ", type: "人なつっこいコアラ"}, | |
{animal: "さる", type: "いきいきとしたさる"}, | |
{animal: "たぬき", type: "感性豊かなたぬき"}, | |
{animal: "チーター", type: "世渡り上手なチーター"}, | |
{animal: "トラ", type: "堂々としたトラ"}, | |
{animal: "ひょう", type: "アイデアマンの黒ひょう"}, | |
{animal: "ライオン", type: "我が道を行くライオン"}, | |
{animal: "ライオン", type: "慎重なライオン"}, | |
{animal: "ひょう", type: "センスの良い黒ひょう"}, | |
{animal: "トラ", type: "フランクなトラ"}, | |
{animal: "トラ", type: "パワフルなトラ"}, | |
{animal: "ひょう", type: "誠実な黒ひょう"}, | |
{animal: "ライオン", type: "親分肌なライオン"}, | |
{animal: "ライオン", type: "どーんと構えているライオン"}, | |
{animal: "ひょう", type: "前向きな黒ひょう"}, | |
] |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Animal</title> | |
<script src="animals.js"></script> | |
<script src="animal.js"></script> | |
<script> | |
var animal = new Animal(animals); | |
console.log(animal.get('1967/03/01')); | |
console.log(animal.get('1974/02/13').animal); | |
console.log(animal.get('1967/01/02').number == 3); | |
console.log(animal.get('1967/01/01').number == 2); | |
console.log(animal.get('1966/12/31').number == 1); | |
console.log(animal.get('1966/12/30').number == 0); | |
console.log(animal.get('1966/12/29').number == 59); | |
console.log(animal.get('1966/12/28').number == 58); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment