Skip to content

Instantly share code, notes, and snippets.

@monsat
Forked from anonymous/index.html
Last active December 15, 2015 23:49

Revisions

  1. monsat revised this gist Apr 9, 2013. 2 changed files with 16 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions animal.js
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    function Animal(data) {
    this.data = data;
    this.base = '1966/12/31';
    this.count = data.length;
    }

    Animal.prototype.get = function(birthday) {
    @@ -11,9 +12,13 @@ Animal.prototype.get = function(birthday) {
    }

    Animal.prototype.number = function(birthday) {
    date = this.strtotime(birthday);
    date -= this.strtotime(this.base) - 1;
    return date % 60;
    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) {
    8 changes: 8 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,16 @@
    <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>
  2. monsat revised this gist Apr 9, 2013. 3 changed files with 91 additions and 1 deletion.
    25 changes: 25 additions & 0 deletions animal.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    function Animal(data) {
    this.data = data;
    this.base = '1966/12/31';
    }

    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) {
    date = this.strtotime(birthday);
    date -= this.strtotime(this.base) - 1;
    return date % 60;
    }

    Animal.prototype.strtotime = function(date) {
    var HOUR = 1000 * 60 * 60;
    var date = Date.parse(date);
    date += HOUR * 9;
    date /= (HOUR * 24);
    return date;
    }
    62 changes: 62 additions & 0 deletions animals.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,62 @@
    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: "前向きな黒ひょう"},
    ]
    5 changes: 4 additions & 1 deletion index.html
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,14 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <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);
    </script>
    </head>
    <body>
  3. @invalid-email-address Anonymous created this gist Apr 9, 2013.
    14 changes: 14 additions & 0 deletions index.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Animal</title>
    <script src="animals.js"></script>
    <script src="animal.js"></script>
    <script>
    </script>
    </head>
    <body>

    </body>
    </html>