feat(name): added constant names

This commit is contained in:
Miguel Caro 2022-01-31 20:39:30 -05:00
parent e0d2e5c555
commit 6468212b02
2 changed files with 44 additions and 23 deletions

3
.prettierrc Normal file
View File

@ -0,0 +1,3 @@
{
"singleQuote": true
}

View File

@ -10,6 +10,18 @@ export class Item {
}
}
enum ItemType {
AgedBrie = 'Aged Brie',
BackstagePasses = 'Backstage passes to a TAFKAL80ETC concert',
Sulfuras = 'Sulfuras, Hand of Ragnaros',
}
const TEN_DAYS_FOR_THE_CONCERT = 11;
const FIVE_DAYS_FOR_THE_CONCERT = 6;
const ZERO_DAYS_FOR_SALE = 0;
const MAX_QUALITY = 50;
const MIN_QUALITY = 0;
export class GildedRose {
items: Array<Item>;
@ -19,46 +31,52 @@ 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
if (
this.items[i].name != ItemType.AgedBrie &&
this.items[i].name != ItemType.BackstagePasses
) {
if (this.items[i].quality > MIN_QUALITY) {
if (this.items[i].name != ItemType.Sulfuras) {
this.items[i].quality = this.items[i].quality - 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 (this.items[i].quality < MAX_QUALITY) {
this.items[i].quality = this.items[i].quality + 1;
if (this.items[i].name == ItemType.BackstagePasses) {
if (this.items[i].sellIn < TEN_DAYS_FOR_THE_CONCERT) {
if (this.items[i].quality < MAX_QUALITY) {
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 < FIVE_DAYS_FOR_THE_CONCERT) {
if (this.items[i].quality < MAX_QUALITY) {
this.items[i].quality = this.items[i].quality + 1;
}
}
}
}
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
if (this.items[i].name != ItemType.Sulfuras) {
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].sellIn < ZERO_DAYS_FOR_SALE) {
if (this.items[i].name != ItemType.AgedBrie) {
if (this.items[i].name != ItemType.BackstagePasses) {
if (this.items[i].quality > MIN_QUALITY) {
if (this.items[i].name != ItemType.Sulfuras) {
this.items[i].quality = this.items[i].quality - 1;
}
}
} else {
this.items[i].quality = this.items[i].quality - this.items[i].quality
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 (this.items[i].quality < MAX_QUALITY) {
this.items[i].quality = this.items[i].quality + 1;
}
}
}