forked from exercism/DEPRECATED.javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
39 lines (31 loc) · 873 Bytes
/
Copy pathexample.js
File metadata and controls
39 lines (31 loc) · 873 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'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;