forked from kajabi-mike/gilded-rose-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgilded-rose.js
More file actions
59 lines (57 loc) · 1.63 KB
/
gilded-rose.js
File metadata and controls
59 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Advances an item by one day, updating its sellIn and quality.
* @param {{ name: string, sellIn: number, quality: number }} item
* @returns {{ name: string, sellIn: number, quality: number }} The same item, mutated.
* @example
* tick({ name: "+5 Dexterity Vest", sellIn: 10, quality: 20 });
* // => { name: "+5 Dexterity Vest", sellIn: 9, quality: 19 }
*/
module.exports = function tick(item) {
if (
item.name !== "Aged Brie" &&
item.name !== "Backstage passes to a TAFKAL80ETC concert"
) {
if (item.quality > 0) {
if (item.name !== "Sulfuras, Hand of Ragnaros") {
item.quality = item.quality - 1;
}
}
} else {
if (item.quality < 50) {
item.quality = item.quality + 1;
if (item.name === "Backstage passes to a TAFKAL80ETC concert") {
if (item.sellIn < 11) {
if (item.quality < 50) {
item.quality = item.quality + 1;
}
}
if (item.sellIn < 6) {
if (item.quality < 50) {
item.quality = item.quality + 1;
}
}
}
}
}
if (item.name !== "Sulfuras, Hand of Ragnaros") {
item.sellIn = item.sellIn - 1;
}
if (item.sellIn < 0) {
if (item.name !== "Aged Brie") {
if (item.name !== "Backstage passes to a TAFKAL80ETC concert") {
if (item.quality > 0) {
if (item.name !== "Sulfuras, Hand of Ragnaros") {
item.quality = item.quality - 1;
}
}
} else {
item.quality = item.quality - item.quality;
}
} else {
if (item.quality < 50) {
item.quality = item.quality + 1;
}
}
}
return item;
};