Skip to content

PR after refactoring. #43

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 5 commits 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: 21 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
name: Run Tests

on:
on: [push, pull_request]

jobs:
test:
runs-on: windows-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install dependencies
run: npm ci

- name: Compile TypeScript
run: npx tsc --noEmit

- name: Run tests
run: npm run test:jest
98 changes: 41 additions & 57 deletions app/gilded-rose.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,53 @@
export class Item {
name: string;
sellIn: number;
quality: number;
name: string;
sellIn: number;
quality: number;

constructor(name, sellIn, quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
constructor(name, sellIn, quality) {
this.name = name;
this.sellIn = sellIn;
this.quality = quality;
}
}

export class GildedRose {
items: Array<Item>;
items: Array<Item>;

constructor(items = [] as Array<Item>) {
this.items = items;
}
constructor(items = [] as Array<Item>) {
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
}
}
} 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
}
}
}
}
updateQuality() {
for (let i = 0; i < this.items.length; i++) {
if (!this.items[i].name.startsWith("Conjured")) {
if (this.items[i].name != "Sulfuras") {
if (this.items[i].quality > 50) this.items[i].quality = 50;
if (
this.items[i].name != "Aged Brie" &&
this.items[i].name != "Backstage passes"
) {
if (this.items[i].sellIn < 0) {
if (this.items[i].quality > 0) this.items[i].quality -= 2;
else this.items[i].quality = 0;
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sellIn = this.items[i].sellIn - 1;
} else {
if (this.items[i].name == "Aged Brie") {
if (this.items[i].sellIn < 0)
this.items[i].quality =
this.items[i].quality - this.items[i].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 (this.items[i].name == "Backstage passes") {
if (this.items[i].sellIn > 3 && this.items[i].sellIn < 10)
this.items[i].quality += 2;
if (this.items[i].sellIn < 5) this.items[i].quality += 3;
}
}
}

return this.items;
} else {
if (this.items[i].quality) this.items[i].quality -= 4;
else this.items[i].quality = 0;
}
}
}
return this.items;
}
}
Loading