fix: code

This commit is contained in:
Mohit 2023-01-16 20:59:39 -08:00
parent 100fb3620a
commit cb735ed585

View File

@ -1,5 +1,5 @@
class Item { class Item {
constructor(name, sellIn, quality){ constructor(name, sellIn, quality) {
this.name = name; this.name = name;
this.sellIn = sellIn; this.sellIn = sellIn;
this.quality = quality; this.quality = quality;
@ -7,55 +7,54 @@ class Item {
} }
class Shop { class Shop {
constructor(items=[]){ constructor(items = []) {
this.items = items; this.items = items;
} }
updateQuality() { updateQuality() {
for (let i = 0; i < this.items.length; i++) { this.items.forEach(item => {
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].quality > 0) { // Define multiplier to 2 if expiration date has passed else set to 1
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { const multiplier = item.sellIn < 0 ? 2 : 1
this.items[i].quality = this.items[i].quality - 1;
switch (item.name) {
case 'Aged Brie':
item.quality++;
item.sellIn--;
break;
case 'Backstage passes to a TAFKAL80ETC concert':
switch (true) {
case (item.sellIn < 0):
item.quality = 0;
break;
case (item.sellIn <= 5):
item.quality += 3;
break;
case (item.sellIn <= 10):
item.quality += 2;
break;
default:
item.quality++;
break;
} }
} item.sellIn--;
} else { break;
if (this.items[i].quality < 50) { case 'Sulfuras, Hand of Ragnaros':
this.items[i].quality = this.items[i].quality + 1; break;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { case 'Conjured Mana Cake':
if (this.items[i].sellIn < 11) { item.quality -= (2 * multiplier);
if (this.items[i].quality < 50) { item.sellIn--;
this.items[i].quality = this.items[i].quality + 1; break;
} default:
} item.quality -= (1 * multiplier);
if (this.items[i].sellIn < 6) { item.sellIn--;
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1;
}
}
}
}
} }
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1; // Item quality cannot be greater than 50 or smaller than 0.
} if (item.quality > 50) item.quality = 50;
if (this.items[i].sellIn < 0) { if (item.quality < 0) item.quality = 0;
if (this.items[i].name != 'Aged Brie') {
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { });
if (this.items[i].quality > 0) {
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].quality = this.items[i].quality - 1;
}
}
} else {
this.items[i].quality = this.items[i].quality - this.items[i].quality;
}
} else {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1;
}
}
}
}
return this.items; return this.items;
} }