Skip to content

Add logic for Conjured Mana Cake#1

Open
AlanProphettSoftwire wants to merge 4 commits intomainfrom
add-logic-for-conjured-mana-cake
Open

Add logic for Conjured Mana Cake#1
AlanProphettSoftwire wants to merge 4 commits intomainfrom
add-logic-for-conjured-mana-cake

Conversation

@AlanProphettSoftwire
Copy link
Copy Markdown
Owner

@AlanProphettSoftwire AlanProphettSoftwire commented Sep 25, 2025

Introduction ✏️

Add logic for Conjured Mana Cake. This item depreciates in quality twice as fast as a standard item.
Conjured Mana Cake has a depreciation of 2 if the sellIn is >=0 and a depreciation of 4 is the sellIn date is <0.

Resolution ✔️

  • Added units tests to capture the expected behavior.
  • Added a switch case to updateQuality to set behavior for non standard items.
  • If the item is a Conjured Mana Cake, depreciate the quality at twice the rate of a standard item.

Note ⚠️

  • The snapshot test was updated to reflect the new functionality.

Co-authored-by: tmgls <tmgls@users.noreply.github.com>
Co-authored-by: tmgls <tmgls@users.noreply.github.com>
Copy link
Copy Markdown

@LukeJStuart LukeJStuart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job adding this new functionality, I added some comments but have realised they are refacotring suggestions and this PR is about adding the new logic, so may be superfluous

@@ -19,50 +19,52 @@ export class GildedRose {

updateQuality() {
for (let i = 0; i < this.items.length; i++) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could consider doing something like for (const item of this.items) and then referring to item so you don't have to keep repeating this.items[i]

break;
case "Aged Brie":
if (this.items[i].sellIn < 0) {
this.items[i].quality = Math.min(this.items[i].quality + 2, 50);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could pull out values like 50 here into well-named consts to increase clarity and reduce risk of typos

if (this.items[i].sellIn < 0) {
this.items[i].quality = Math.min(this.items[i].quality + 2, 50);
} else {
this.items[i].quality = Math.min(this.items[i].quality + 1, 50);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could create a helper function for clamping values so don't need to repeatedly use Math.min and Math.max throughout the switch statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants