From bfb20fbad4ab3ddb43a4ebda49cc37987d7082d4 Mon Sep 17 00:00:00 2001 From: wengYuting Date: Thu, 7 Apr 2022 16:53:24 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=87=8D=E6=A7=8B]=20=E5=90=88=E4=BD=B5?= =?UTF-8?q?=E3=80=81=E6=B8=9B=E5=B0=91=E5=88=A4=E6=96=B7=E5=BC=8F=E5=B1=A4?= =?UTF-8?q?=E6=95=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js-jest/src/gilded_rose.js | 76 ++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 32 deletions(-) diff --git a/js-jest/src/gilded_rose.js b/js-jest/src/gilded_rose.js index 48746965..3d968858 100644 --- a/js-jest/src/gilded_rose.js +++ b/js-jest/src/gilded_rose.js @@ -1,5 +1,5 @@ class Item { - constructor(name, sellIn, quality){ + constructor(name, sellIn, quality) { this.name = name; this.sellIn = sellIn; this.quality = quality; @@ -7,52 +7,64 @@ class Item { } class Shop { - constructor(items=[]){ + constructor(items = []) { this.items = items; } + /* + 反轉負向判定(!) + 中斷程式碼簡化判定 + 整合判定(sellIn 變動提到前面拉齊比對基準) + 各商品行為抽成單獨的 function + updateQuality => updateItem? + */ + updateQuality() { 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; - } - } - } else { + if ( + this.items[i].name === "Aged Brie" || + this.items[i].name === "Backstage passes to a TAFKAL80ETC concert" + ) { if (this.items[i].quality < 50) { this.items[i].quality = 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].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; - } + if ( + this.items[i].name == "Backstage passes to a TAFKAL80ETC concert" + ) { + if (this.items[i].sellIn < 11 && this.items[i].quality < 50) { + this.items[i].quality = this.items[i].quality + 1; } - 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 < 6 && this.items[i].quality < 50) { + this.items[i].quality = this.items[i].quality + 1; } } } + } else if ( + this.items[i].quality > 0 && + this.items[i].name != "Sulfuras, Hand of Ragnaros" + ) { + this.items[i].quality = this.items[i].quality - 1; } - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { + + if (this.items[i].name != "Sulfuras, Hand of Ragnaros") { this.items[i].sellIn = 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].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1; - } + if (this.items[i].name != "Aged Brie") { + if ( + this.items[i].name != "Backstage passes to a TAFKAL80ETC concert" + ) { + if ( + this.items[i].quality > 0 && + this.items[i].name != "Sulfuras, Hand of Ragnaros" + ) { + this.items[i].quality = this.items[i].quality - 1; } } else { - this.items[i].quality = this.items[i].quality - this.items[i].quality; - } - } else { - if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1; + this.items[i].quality = + this.items[i].quality - this.items[i].quality; } + } else if (this.items[i].quality < 50) { + this.items[i].quality = this.items[i].quality + 1; } } } @@ -63,5 +75,5 @@ class Shop { module.exports = { Item, - Shop -} + Shop, +};