Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 29 additions & 34 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,46 @@ export class GildedRose {

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
}
const isAgedBrie = this.items[i].name === 'Aged Brie';
const isBackstage = this.items[i].name === 'Backstage passes to a TAFKAL80ETC concert';
const isSulfuras = this.items[i].name === 'Sulfuras, Hand of Ragnaros';
const isConjured = this.items[i].name.startsWith('Conjured');

// Quality update before sellIn
if (!isAgedBrie && !isBackstage) {
if (!isSulfuras && this.items[i].quality > 0) {
this.items[i].quality -= isConjured ? 2 : 1;
if (this.items[i].quality < 0) this.items[i].quality = 0;
}
} 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 (this.items[i].sellIn < 6) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
}
}
this.items[i].quality += 1;
if (isBackstage) {
if (this.items[i].sellIn < 11 && this.items[i].quality < 50) this.items[i].quality += 1;
if (this.items[i].sellIn < 6 && this.items[i].quality < 50) this.items[i].quality += 1;
}
}
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;

// SellIn update
if (!isSulfuras) {
this.items[i].sellIn -= 1;
}

// Quality update after sellIn
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
}
}
} 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
}
if (isAgedBrie && this.items[i].quality < 50) {
this.items[i].quality += 1;
} else if (isBackstage) {
this.items[i].quality = 0;
} else if (!isSulfuras && this.items[i].quality > 0) {
this.items[i].quality -= isConjured ? 2 : 1;
if (this.items[i].quality < 0) this.items[i].quality = 0;
}
}
}

return this.items;

}
}
105 changes: 66 additions & 39 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
"rimraf": "~3.0.2",
"source-map-support": "^0.5.20",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0",
"ts-node": "^10.9.2",
"tsconfig-paths": "^3.11.0",
"typescript": "^4.4.4"
"typescript": "^4.9.5"
}
}
Loading