Extract backstage pass logic

This commit is contained in:
Dan Holmes 2020-12-03 14:49:07 +00:00
parent 9eb17f67da
commit 11042aa5de

View File

@ -12,39 +12,43 @@ class Shop {
}
_updateItemQuality(item) {
if (item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert') {
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.quality = item.quality - 1;
}
if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
this._updateQualityBackstagePass(item)
} else {
item.quality = item.quality + 1;
if (item.name == 'Backstage passes to a TAFKAL80ETC concert') {
if (item.sellIn < 11) {
item.quality = item.quality + 1;
}
if (item.sellIn < 6) {
item.quality = item.quality + 1;
}
}
}
this._updateSellIn(item)
if (item.sellIn < 0) {
if (item.name != 'Aged Brie') {
if (item.name != 'Backstage passes to a TAFKAL80ETC concert') {
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.quality = item.quality - 1;
}
} else {
item.quality = item.quality - item.quality;
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.quality = item.quality - 1;
}
} else {
item.quality = item.quality + 1;
}
this._updateSellIn(item)
if (item.sellIn < 0) {
if (item.name != 'Aged Brie') {
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.quality = item.quality - 1;
}
} else {
item.quality = item.quality + 1;
}
}
}
this._checkMaxQuality(item);
this._checkMinQuality(item);
}
_updateQualityBackstagePass(item) {
if (item.sellIn <= 0) {
item.quality = 0;
} else if (item.sellIn < 6) {
item.quality += 3;
} else if (item.sellIn < 11) {
item.quality += 2;
} else {
item.quality += 1;
}
}
_updateSellIn(item) {
if (item.name != 'Sulfuras, Hand of Ragnaros') {
item.sellIn = item.sellIn - 1;