From 9eb17f67da3114ba42f735a4ee59c58747e9514c Mon Sep 17 00:00:00 2001 From: Dan Holmes Date: Thu, 3 Dec 2020 14:40:22 +0000 Subject: [PATCH] Extract min quality checks --- js-jasmine/src/shop.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/js-jasmine/src/shop.js b/js-jasmine/src/shop.js index 6adcc218..9eb04191 100644 --- a/js-jasmine/src/shop.js +++ b/js-jasmine/src/shop.js @@ -2,6 +2,7 @@ class Shop { constructor(items = []) { this.items = items; this.MAX_QUALITY = 50; + this.MIN_QUALITY = 0; } updateQuality() { for (var i = 0; i < this.items.length; i++) { @@ -12,10 +13,8 @@ class Shop { _updateItemQuality(item) { if (item.name != 'Aged Brie' && item.name != 'Backstage passes to a TAFKAL80ETC concert') { - if (item.quality > 0) { - if (item.name != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1; - } + if (item.name != 'Sulfuras, Hand of Ragnaros') { + item.quality = item.quality - 1; } } else { item.quality = item.quality + 1; @@ -32,10 +31,8 @@ class Shop { if (item.sellIn < 0) { if (item.name != 'Aged Brie') { if (item.name != 'Backstage passes to a TAFKAL80ETC concert') { - if (item.quality > 0) { - if (item.name != 'Sulfuras, Hand of Ragnaros') { - item.quality = item.quality - 1; - } + if (item.name != 'Sulfuras, Hand of Ragnaros') { + item.quality = item.quality - 1; } } else { item.quality = item.quality - item.quality; @@ -45,6 +42,7 @@ class Shop { } } this._checkMaxQuality(item); + this._checkMinQuality(item); } _updateSellIn(item) { @@ -58,6 +56,12 @@ class Shop { item.quality = this.MAX_QUALITY; } } + + _checkMinQuality(item) { + if (item.quality < this.MIN_QUALITY) { + item.quality = this.MIN_QUALITY; + } + } } module.exports = { Shop