-
Notifications
You must be signed in to change notification settings - Fork 174
/
pharmacy.js
66 lines (64 loc) · 1.9 KB
/
pharmacy.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
export class Drug {
constructor(name, expiresIn, benefit) {
this.name = name;
this.expiresIn = expiresIn;
this.benefit = benefit;
}
}
export class Pharmacy {
constructor(drugs = []) {
this.drugs = drugs;
}
updateBenefitValue() {
for (var i = 0; i < this.drugs.length; i++) {
if (
this.drugs[i].name != "Herbal Tea" &&
this.drugs[i].name != "Fervex"
) {
if (this.drugs[i].benefit > 0) {
if (this.drugs[i].name != "Magic Pill") {
this.drugs[i].benefit = this.drugs[i].benefit - 1;
}
}
} else {
if (this.drugs[i].benefit < 50) {
this.drugs[i].benefit = this.drugs[i].benefit + 1;
if (this.drugs[i].name == "Fervex") {
if (this.drugs[i].expiresIn < 11) {
if (this.drugs[i].benefit < 50) {
this.drugs[i].benefit = this.drugs[i].benefit + 1;
}
}
if (this.drugs[i].expiresIn < 6) {
if (this.drugs[i].benefit < 50) {
this.drugs[i].benefit = this.drugs[i].benefit + 1;
}
}
}
}
}
if (this.drugs[i].name != "Magic Pill") {
this.drugs[i].expiresIn = this.drugs[i].expiresIn - 1;
}
if (this.drugs[i].expiresIn < 0) {
if (this.drugs[i].name != "Herbal Tea") {
if (this.drugs[i].name != "Fervex") {
if (this.drugs[i].benefit > 0) {
if (this.drugs[i].name != "Magic Pill") {
this.drugs[i].benefit = this.drugs[i].benefit - 1;
}
}
} else {
this.drugs[i].benefit =
this.drugs[i].benefit - this.drugs[i].benefit;
}
} else {
if (this.drugs[i].benefit < 50) {
this.drugs[i].benefit = this.drugs[i].benefit + 1;
}
}
}
}
return this.drugs;
}
}