Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring 1 #2

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
57 changes: 31 additions & 26 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,56 @@ export class GildedRose {
this.items = items;
}


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
}
}

let itemName = this.items[i].name;
let itemQuality = this.items[i].quality;
let itemSell_in = this.items[i].sellIn;

if (itemName != 'Aged Brie' && itemName != 'Backstage passes to a TAFKAL80ETC concert' && itemName != 'Sulfuras, Hand of Ragnaros') {
itemQuality = itemQuality == 0? 0: itemQuality-1 ;

} else {
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 (itemQuality < 50) {
itemQuality += 1
if (itemName == 'Backstage passes to a TAFKAL80ETC concert') {
if (itemSell_in< 11) {
if (itemQuality < 50) {
itemQuality += 1;
}
}
if (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
if (itemSell_in< 6) {
if (itemQuality < 50) {
itemQuality += 1 ;
}
}
}
}
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;
if (itemName != 'Sulfuras, Hand of Ragnaros') {
itemSell_in -= 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 (itemSell_in < 0) {
if (itemName != 'Aged Brie') {
if (itemName != 'Backstage passes to a TAFKAL80ETC concert') {
if (itemQuality> 0) {
if (itemName != 'Sulfuras, Hand of Ragnaros') {
itemQuality -= 1;
}
}
} else {
this.items[i].quality = this.items[i].quality - this.items[i].quality
itemQuality = 0;
}
} else {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
if (itemQuality < 50) {
itemQuality += 1
}
}
}
this.items[i].quality = itemQuality;
this.items[i].sellIn = itemSell_in;
}

return this.items;
Expand Down
Loading