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.58 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.57 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.56 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.55 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.54 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.53 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.52 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.51 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.50 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.49 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.48 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.47 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.46 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.45 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.44 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.43 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.42 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.41 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.40 tracks/javascript/exercises/allergies/example.js
trackler-2.2.1.39 tracks/javascript/exercises/allergies/example.js