Merge pull request #1 from dudeitsjesse/dudeitsjesse-patch-1

refactor updateQuality and add support for conjured items
This commit is contained in:
dudeitsjesse 2018-07-06 14:33:06 -07:00 committed by GitHub
commit c50323d76c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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,56 +7,55 @@ class Item {
} }
class Shop { class Shop {
constructor(items=[]){ constructor(items = []) {
this.items = items; this.items = items;
} }
updateQuality() { increaseQuality(item) {
for (var i = 0; i < this.items.length; i++) { if (item.quality < 50) {
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { item.quality++;
if (this.items[i].quality > 0) { }
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { return item;
this.items[i].quality = this.items[i].quality - 1; }
} decreaseQuality(item) {
} if (item.quality > 0) {
if (item.sellIn < 0 || item.name === 'Conjured Mana Cake') {
item.quality = item.quality - 2 > 0 ? item.quality - 2 : 0;
} else { } else {
if (this.items[i].quality < 50) { item.quality--;
this.items[i].quality = this.items[i].quality + 1;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].sellIn < 11) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1;
}
}
if (this.items[i].sellIn < 6) {
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;
}
if (this.items[i].sellIn < 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 item;
}
updateQuality() {
this.items.map(item => {
switch (item.name) {
case 'Aged Brie':
this.increaseQuality(item);
item.sellIn--;
break;
case 'Backstage passes to a TAFKAL80ETC concert':
if (item.sellIn > 0) {
this.increaseQuality(item);
if (item.sellIn < 11) {
this.increaseQuality(item);
}
if (item.sellIn < 6) {
this.increaseQuality(item);
}
} else {
item.quality = 0;
}
item.sellIn--;
break;
case 'Sulfuras, Hand of Ragnaros':
item.sellIn--;
break;
default:
this.decreaseQuality(item);
item.sellIn--;
}
});
return this.items; return this.items;
} }
} }