From a06e2211971c9c014322e16609f4447a6144bbbe Mon Sep 17 00:00:00 2001 From: Jesper Date: Wed, 13 Apr 2022 16:57:38 +0200 Subject: [PATCH] Flatten conditionals --- TypeScript/app/gilded-rose.ts | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/TypeScript/app/gilded-rose.ts b/TypeScript/app/gilded-rose.ts index 08c96785..e1fdd2c6 100644 --- a/TypeScript/app/gilded-rose.ts +++ b/TypeScript/app/gilded-rose.ts @@ -19,22 +19,16 @@ export class GildedRose { updateQuality() { this.items.forEach((item, i) => { - if (item.name == 'Aged Brie' || item.name == 'Backstage passes to a TAFKAL80ETC concert') { - if (item.name == 'Aged Brie') { - this.incrementQuality(item); - } - - 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) { - if (item.name != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1 - } - } + 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 } if (item.name != 'Sulfuras, Hand of Ragnaros') { item.sellIn = item.sellIn - 1;