From ba05d9fb40d8431485017fbb1ec14b629a2852ba Mon Sep 17 00:00:00 2001 From: Ben Hemann Date: Mon, 7 Jun 2021 14:07:51 -0500 Subject: [PATCH] basic refactoring done, added min and max variables, changed addition and subtraction of quality; --- TypeScript/app/gilded-rose.ts | 39 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/TypeScript/app/gilded-rose.ts b/TypeScript/app/gilded-rose.ts index 6a71233b..f4083755 100644 --- a/TypeScript/app/gilded-rose.ts +++ b/TypeScript/app/gilded-rose.ts @@ -20,27 +20,26 @@ export class GildedRose { // Method for updating item quality updateQuality() { + var maxQuality = 50; + var minQuality = 0; 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') { - if (this.items[i].quality > 0) { - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1 - } - } + 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) { + this.items[i].quality -=1; } else { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + 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].sellIn < 11) { + if (this.items[i].sellIn <= 10) { // quality goes up by 2 when days are 10 or less - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + if (this.items[i].quality < maxQuality) { + this.items[i].quality += 1; } } // quality goes up by 3 when days are 5 of less - 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].sellIn <= 5) { + if (this.items[i].quality < maxQuality) { + this.items[i].quality += 1; } } } @@ -48,26 +47,26 @@ export class GildedRose { } // checking for legendary to subtract sell by date if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].sellIn = this.items[i].sellIn - 1; + 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].quality > minQuality) { // move this if above line 57 if if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1 + this.items[i].quality -= 1; } } } else { - this.items[i].quality = this.items[i].quality - this.items[i].quality + this.items[i].quality -= this.items[i].quality; } // aged brie increases in quality here } else { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + if (this.items[i].quality < maxQuality) { + this.items[i].quality += 1; } } }