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.180 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.179 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.178 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.177 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.176 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.175 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.174 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.173 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.172 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.171 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.170 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.169 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.167 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.166 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.165 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.164 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.163 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.162 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.161 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.160 tracks/javascript/exercises/allergies/example.js