Advertisement
LynchzDEV

gilded-rose.ts

Nov 17th, 2024 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TypeScript 2.28 KB | Source Code | 0 0
  1. export class Item {
  2.   name: string;
  3.   sellIn: number;
  4.   quality: number;
  5.  
  6.   constructor(name, sellIn, quality) {
  7.     this.name = name;
  8.     this.sellIn = sellIn;
  9.     this.quality = quality;
  10.   }
  11. }
  12.  
  13. export class GildedRose {
  14.   items: Array<Item>;
  15.  
  16.   constructor(items = [] as Array<Item>) {
  17.     this.items = items;
  18.   }
  19.  
  20.   updateQuality() {
  21.     for (let i = 0; i < this.items.length; i++) {
  22.       if (
  23.         ["Aged Brie", "Backstage passes to a TAFKAL80ETC concert"].includes(
  24.           this.items[i].name,
  25.         )
  26.       ) {
  27.         if (this.items[i].quality < 50) {
  28.           if (
  29.             this.items[i].sellIn < 6 &&
  30.             this.items[i].quality < 50 &&
  31.             this.items[i].name == "Backstage passes to a TAFKAL80ETC concert"
  32.           ) {
  33.             this.items[i].quality = this.items[i].quality + 3;
  34.           } else if (
  35.             this.items[i].sellIn < 11 &&
  36.             this.items[i].quality < 50 &&
  37.             this.items[i].name == "Backstage passes to a TAFKAL80ETC concert"
  38.           ) {
  39.             this.items[i].quality = this.items[i].quality + 2;
  40.           } else {
  41.             this.items[i].quality = this.items[i].quality + 1;
  42.           }
  43.         }
  44.       } else {
  45.         if (this.items[i].quality > 0) {
  46.           if (this.items[i].name != "Sulfuras, Hand of Ragnaros") {
  47.             this.items[i].quality = this.items[i].quality - 1;
  48.           }
  49.         }
  50.       }
  51.  
  52.       if (this.items[i].name != "Sulfuras, Hand of Ragnaros") {
  53.         this.items[i].sellIn = this.items[i].sellIn - 1;
  54.       }
  55.  
  56.       if (this.items[i].sellIn < 0) {
  57.         if (this.items[i].name == "Aged Brie") {
  58.           if (this.items[i].quality < 50) {
  59.             this.items[i].quality = this.items[i].quality + 1;
  60.           }
  61.         } else {
  62.           if (
  63.             this.items[i].name == "Backstage passes to a TAFKAL80ETC concert"
  64.           ) {
  65.             this.items[i].quality =
  66.               this.items[i].quality - this.items[i].quality;
  67.           } else {
  68.             if (this.items[i].quality > 0) {
  69.               if (this.items[i].name != "Sulfuras, Hand of Ragnaros") {
  70.                 this.items[i].quality = this.items[i].quality - 1;
  71.               }
  72.             }
  73.           }
  74.         }
  75.       }
  76.     }
  77.  
  78.     return this.items;
  79.   }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement