more minor refactor done, want to try forEach or break up ifs

This commit is contained in:
Ben Hemann 2021-06-07 16:43:42 -05:00
parent 57f1bb484a
commit 1ad69417cc

View File

@ -23,14 +23,18 @@ export class GildedRose {
var maxQuality = 50;
var minQuality = 0;
var conjured = 'Conjured';
var hand = 'Sulfuras, Hand of Ragnaros';
var cheese = 'Aged Brie';
var pass = 'Backstage passes to a TAFKAL80ETC concert';
for (let i = 0; i < this.items.length; i++) {
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert'
&& this.items[i].name != 'Sulfuras, Hand of Ragnaros' && this.items[i].quality >minQuality) {
if (this.items[i].name != cheese && this.items[i].name != pass
&& this.items[i].name != hand && this.items[i].quality > minQuality) {
this.items[i].quality -=1;
} else {
if (this.items[i].quality < maxQuality) {
this.items[i].quality += 1;
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
if (this.items[i].name == pass) {
if (this.items[i].sellIn <= 10 && this.items[i].sellIn > 5) {
// quality goes up by 2 when days are 10 or less
if (this.items[i].quality < maxQuality) {
@ -47,16 +51,16 @@ export class GildedRose {
}
}
// checking for legendary to subtract sell by date
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
if (this.items[i].name != hand) {
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].name != cheese) {
if (this.items[i].name != pass) {
if (this.items[i].quality > minQuality) {
// move this if above line 57 if
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
if (this.items[i].name != hand) {
this.items[i].quality -= 1;
}
}
@ -65,14 +69,15 @@ export class GildedRose {
this.items[i].quality = 0;
}
// aged brie increases in quality here
} else if (this.items[i].name == 'Aged Brie') {
} else if (this.items[i].name == cheese) {
if (this.items[i].quality < maxQuality) {
this.items[i].quality += 1;
}
}
}
}
return this.items;
}
}
}// end class