mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
- I've started with a small refactor, Command to function. This was done as the most obvious way to do it (to me) as in the original, would not compile in Nim due to violating memory lifetimes. I could have made it take a ref seq[Item], but then I would need to instatiate a ref seq and I didn't want to make a change that drastic. Also due to Nim's UFCS, the ultimate implementation would be basically the same anyway.
36 lines
1.3 KiB
Nim
36 lines
1.3 KiB
Nim
import items
|
|
|
|
proc updateQuality*(items: var seq[Item]) =
|
|
for i in 0 ..< items.len:
|
|
if items[i].name != "Aged Brie" and items[i].name != "Backstage passes to a TAFKAL80ETC concert":
|
|
if items[i].quality > 0:
|
|
if items[i].name != "Sulfuras, Hand of Ragnaros":
|
|
items[i].quality = items[i].quality - 1
|
|
else:
|
|
if items[i].quality < 50:
|
|
items[i].quality = items[i].quality + 1
|
|
|
|
if items[i].name == "Backstage passes to a TAFKAL80ETC concert":
|
|
if items[i].sellIn < 11:
|
|
if items[i].quality < 50:
|
|
items[i].quality = items[i].quality + 1
|
|
|
|
if items[i].sellIn < 6:
|
|
if items[i].quality < 50:
|
|
items[i].quality = items[i].quality + 1
|
|
|
|
if items[i].name != "Sulfuras, Hand of Ragnaros":
|
|
items[i].sellIn = items[i].sellIn - 1
|
|
|
|
if items[i].sellIn < 0:
|
|
if items[i].name != "Aged Brie":
|
|
if items[i].name != "Backstage passes to a TAFKAL80ETC concert":
|
|
if items[i].quality > 0:
|
|
if items[i].name != "Sulfuras, Hand of Ragnaros":
|
|
items[i].quality = items[i].quality - 1
|
|
else:
|
|
items[i].quality = items[i].quality - items[i].quality
|
|
else:
|
|
if items[i].quality < 50:
|
|
items[i].quality = items[i].quality + 1
|