Created
November 22, 2019 22:49
-
-
Save mrdougwright/2305d15ceb7b26521c91bbdded884e88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const update = (items) => { | |
items.map(update_item) | |
} | |
const update_item = (item) => { | |
switch (item.name) { | |
case "Sulfuras, Hand of Ragnaros": | |
return item | |
break | |
case "Aged Brie": | |
return constrain_quality(update_brie(update_age(item))) | |
break | |
case "Backstage passes to a TAFKAL80ETC concert": | |
return constrain_quality(update_ticket(item)) | |
break | |
default: | |
return constrain_quality(update_regular_item(update_age(item))) | |
} | |
} | |
const update_brie = (item) => { | |
if (item.sell_in < 0) { | |
item.quality += 2 | |
} else { | |
item.quality += 1 | |
} | |
return item | |
} | |
const update_ticket = (item) => { | |
if (item.sell_in < 0) { | |
item.quality = 0 | |
} else if (item.sell_in < 5) { | |
item.quality += 3 | |
} else if (item.sell_in < 10) { | |
item.quality += 2 | |
} else { | |
item.quality += 1 | |
} | |
return item | |
} | |
const update_regular_item = (item) => { | |
if (item.sell_in < 0) { | |
item.quality -= 2 | |
} else { | |
item.quality -= 1 | |
} | |
return item | |
} | |
const update_age = (item) => { | |
item.sell_in-- | |
return item | |
} | |
const constrain_quality = (item) => { | |
if (item.quality < 0) { | |
item.quality = 0 | |
} else if (item.quality > 50) { | |
item.quality = 50 | |
} | |
return item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment