|
1 | | -export class Pharmacy { |
2 | | - constructor(private readonly drugs = []) {} |
| 1 | +import { Drug } from '../drug/drug'; |
3 | 2 |
|
4 | | - updateBenefitValue() { |
5 | | - for (let i = 0; i < this.drugs.length; i++) { |
6 | | - if ( |
7 | | - this.drugs[i].name != 'Herbal Tea' && |
8 | | - this.drugs[i].name != 'Fervex' |
9 | | - ) { |
10 | | - if (this.drugs[i].benefit > 0) { |
11 | | - if (this.drugs[i].name != 'Magic Pill') { |
12 | | - this.drugs[i].benefit = this.drugs[i].benefit - 1; |
13 | | - } |
14 | | - } |
15 | | - } else { |
16 | | - if (this.drugs[i].benefit < 50) { |
17 | | - this.drugs[i].benefit = this.drugs[i].benefit + 1; |
18 | | - if (this.drugs[i].name == 'Fervex') { |
19 | | - if (this.drugs[i].expiresIn < 11) { |
20 | | - if (this.drugs[i].benefit < 50) { |
21 | | - this.drugs[i].benefit = this.drugs[i].benefit + 1; |
22 | | - } |
23 | | - } |
24 | | - if (this.drugs[i].expiresIn < 6) { |
25 | | - if (this.drugs[i].benefit < 50) { |
26 | | - this.drugs[i].benefit = this.drugs[i].benefit + 1; |
27 | | - } |
28 | | - } |
29 | | - } |
30 | | - } |
31 | | - } |
32 | | - if (this.drugs[i].name != 'Magic Pill') { |
33 | | - this.drugs[i].expiresIn = this.drugs[i].expiresIn - 1; |
34 | | - } |
35 | | - if (this.drugs[i].expiresIn < 0) { |
36 | | - if (this.drugs[i].name != 'Herbal Tea') { |
37 | | - if (this.drugs[i].name != 'Fervex') { |
38 | | - if (this.drugs[i].benefit > 0) { |
39 | | - if (this.drugs[i].name != 'Magic Pill') { |
40 | | - this.drugs[i].benefit = this.drugs[i].benefit - 1; |
41 | | - } |
42 | | - } |
43 | | - } else { |
44 | | - this.drugs[i].benefit = |
45 | | - this.drugs[i].benefit - this.drugs[i].benefit; |
46 | | - } |
47 | | - } else { |
48 | | - if (this.drugs[i].benefit < 50) { |
49 | | - this.drugs[i].benefit = this.drugs[i].benefit + 1; |
50 | | - } |
51 | | - } |
52 | | - } |
53 | | - } |
| 3 | +export class Pharmacy { |
| 4 | + constructor(private readonly drugs: Drug[] = []) {} |
54 | 5 |
|
55 | | - return this.drugs; |
| 6 | + public updateBenefitValue() { |
| 7 | + return this.drugs.map((drug) => drug.updateValues()); |
56 | 8 | } |
57 | 9 | } |
0 commit comments