Extract update item quality

This commit is contained in:
Jesper 2022-04-13 16:59:40 +02:00
parent a06e221197
commit 426d9ecd03

View File

@ -19,27 +19,33 @@ export class GildedRose {
updateQuality() {
this.items.forEach((item, i) => {
if (item.name === 'Sulfuras, Hand of Ragnaros') {
// Do Nothing
} else if (item.name == 'Aged Brie') {
this.incrementQuality(item);
} else if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
this.incrementQuality(item);
if (item.sellIn < 11) this.incrementQuality(item)
if (item.sellIn < 6) this.incrementQuality(item)
} else if (item.quality > 0) {
item.quality = item.quality - 1
}
this.updateItemQuality(item)
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.sellIn = item.sellIn - 1;
}
item.quality = sellInBelow0(item)
})
return this.items;
}
private updateItemQuality(item: Item) {
if (item.name === 'Sulfuras, Hand of Ragnaros') {
return
} else if (item.name == 'Aged Brie') {
this.incrementQuality(item);
} else if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
this.incrementQuality(item);
if (item.sellIn < 11) this.incrementQuality(item)
if (item.sellIn < 6) this.incrementQuality(item)
} else if (item.quality > 0) {
item.quality = item.quality - 1
}
}
private incrementQuality(item: Item) {
if (item.quality < 50) {
item.quality = item.quality + 1;