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.98 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.97 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.96 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.95 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.94 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.93 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.92 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.91 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.90 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.89 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.88 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.87 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.86 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.85 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.84 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.83 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.82 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.81 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.80 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.79 tracks/javascript/exercises/allergies/example.js