diff --git a/TypeScript/src/gilded-rose.ts b/TypeScript/src/gilded-rose.ts index d0bb1868..1c3f0e0f 100644 --- a/TypeScript/src/gilded-rose.ts +++ b/TypeScript/src/gilded-rose.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ export class Item { name: string sellIn: number @@ -20,19 +21,30 @@ export class GildedRose { this.items = items } + // est périmité ? + // should increase quality ? + + shouldDecreaseQuality(item: Item) { + return ( + item.name != 'Aged Brie' && + item.name != 'Backstage passes to a TAFKAL80ETC concert' && + item.quality > 0 + ) + } + + isLegendayProduct(item: Item) { + return item.name === 'Sulfuras, Hand of Ragnaros' + } + updateQuality() { this.items.forEach(item => { + if (this.isLegendayProduct(item)) { + return + } const currentProductName = item.name // PART 1 - if ( - currentProductName != 'Aged Brie' && - currentProductName != 'Backstage passes to a TAFKAL80ETC concert' - ) { - if (item.quality > 0) { - if (currentProductName != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1 - } - } + if (this.shouldDecreaseQuality(item)) { + item.quality = item.quality - 1 } else { if (item.quality < 50) { item.quality = item.quality + 1 @@ -51,17 +63,13 @@ export class GildedRose { } } // part 2 - if (currentProductName != 'Sulfuras, Hand of Ragnaros') { - item.sellIn = item.sellIn - 1 - } + item.sellIn = item.sellIn - 1 // part 3 if (item.sellIn < 0) { if (currentProductName != 'Aged Brie') { if (currentProductName != 'Backstage passes to a TAFKAL80ETC concert') { if (item.quality > 0) { - if (currentProductName != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1 - } + item.quality = item.quality - 1 } } else { item.quality = item.quality - item.quality