From 98b400604e1efa1fe1a9e7604cd2ef316064ec70 Mon Sep 17 00:00:00 2001 From: Chamoda Ranasinghe Date: Tue, 16 Jan 2024 03:20:58 +0700 Subject: [PATCH] cleaned up updateAgedBrieItem method assert AGED_BREE key --- TypeScript/app/gilded-rose.ts | 41 +++++------------------------------ 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/TypeScript/app/gilded-rose.ts b/TypeScript/app/gilded-rose.ts index 8ca32149..06fa865f 100644 --- a/TypeScript/app/gilded-rose.ts +++ b/TypeScript/app/gilded-rose.ts @@ -1,3 +1,4 @@ +import { assert } from "console"; import { ItemNames, MAX_ITEM_QUALITY } from "./constants"; export class Item { @@ -20,47 +21,15 @@ export class GildedRose { } private updateAgedBrieItem(item: Item) { - if ( - item.name != ItemNames.AGED_BRIE && - item.name != ItemNames.BACKSTAGE_PASSES - ) { - if (item.quality > 0) { - if (item.name != ItemNames.SULFURAS) { - item.quality = item.quality - 1; - } - } - } else if (item.quality < MAX_ITEM_QUALITY) { + assert(item.name == ItemNames.AGED_BRIE); + if (item.quality < MAX_ITEM_QUALITY) { item.quality = item.quality + 1; - if (item.name == ItemNames.BACKSTAGE_PASSES) { - if (item.sellIn < 11) { - if (item.quality < MAX_ITEM_QUALITY) { - item.quality = item.quality + 1; - } - } - if (item.sellIn < 6) { - if (item.quality < MAX_ITEM_QUALITY) { - item.quality = item.quality + 1; - } - } - } } if (item.name != ItemNames.SULFURAS) { item.sellIn = item.sellIn - 1; } - if (item.sellIn < 0) { - if (item.name != ItemNames.AGED_BRIE) { - if (item.name != ItemNames.BACKSTAGE_PASSES) { - if (item.quality > 0) { - if (item.name != ItemNames.SULFURAS) { - item.quality = item.quality - 1; - } - } - } else { - item.quality = 0; - } - } else if (item.quality < MAX_ITEM_QUALITY) { - item.quality = item.quality + 1; - } + if (item.sellIn < 0 && item.quality < MAX_ITEM_QUALITY) { + item.quality = item.quality + 1; } }