Skip to content

Added tests & Refactored #28

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
22 changes: 11 additions & 11 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
94 changes: 56 additions & 38 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,71 @@ export class GildedRose {
this.items = items;
}

increaseQuality(item: Item, maxQuality: number) {
if (item.quality < maxQuality) {
item.quality += 1;
}
}

decreaseQuality(item: Item, minQuality: number) {
if (item.quality > minQuality) {
item.quality -= 1;
}
}

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
}
// Sulfuras does not drop in value
if (this.items[i].name == 'Sulfuras, Hand of Ragnaros') {
continue
}

// Decrease the expiration date
this.items[i].sellIn = this.items[i].sellIn - 1;

// Increase the value of brie
if (this.items[i].name == 'Aged Brie') {
this.increaseQuality(this.items[i], 50);

if (this.items[i].sellIn < 0) {
this.increaseQuality(this.items[i], 50);
}
} 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
}
}
}

continue
}

// Increase value based on concert date
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
this.increaseQuality(this.items[i], 50);

if (this.items[i].sellIn < 0) {
this.items[i].quality = 0;
continue
}

if (this.items[i].sellIn < 11) {
this.increaseQuality(this.items[i], 50);
}

if (this.items[i].sellIn < 6) {
this.increaseQuality(this.items[i], 50);
}

continue;
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;

// Decrease value again for conjured items
if (this.items[i].name.toLowerCase().indexOf('conjured') != -1) {
this.decreaseQuality(this.items[i], 0);
}

// Decrease value of default items
this.decreaseQuality(this.items[i], 0);
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
}
}
this.decreaseQuality(this.items[i], 0);
}
}

return this.items;
}
}
}
Loading