Sha256: 62a7a5b6ea9446609d0ae8ad6ca4992976b4d21a99fed2a1609238dabeafa45a

Contents?: true

Size: 873 Bytes

Versions: 141

Compression:

Stored size: 873 Bytes

Contents

'use strict';

function Allergies(allergenIndex) {
  this.allergenIndex = allergenIndex;
}

Allergies.possibleAllergies = [ 'eggs', 'peanuts', 'shellfish', 'strawberries',
  'tomatoes', 'chocolate', 'pollen', 'cats'];

Allergies.prototype = {
  list: function () {
    var possibleAllergies = Allergies.possibleAllergies;

    var allergicTo = [];

    for (var i = 0; i < possibleAllergies.length; i++) {
      var allergy = possibleAllergies[i];
      if (this.allergenIndex & Math.pow(2, i)) {
        allergicTo.push(allergy);
      }
    }
    return allergicTo;
  },
  allergicTo: function (food) {
    var isAllergic = false;

    var allergyList = this.list();
    for (var i = 0; i < allergyList.length; i++) {
      if (allergyList[i] === food) {
        isAllergic = true;
        break;
      }
    }

    return isAllergic;
  }
};

module.exports = Allergies;

Version data entries

141 entries across 141 versions & 1 rubygems

Version Path
trackler-2.2.1.119 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.118 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.117 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.116 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.115 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.114 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.113 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.111 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.110 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.109 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.108 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.107 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.106 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.105 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.104 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.103 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.102 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.101 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.100 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.99 tracks/javascript/exercises/allergies/example.js