All 35 Bugs /
0/35 Fixed ✓
JavaScriptMedium~10 min

Mutating Shared State Object Bug

What's Broken (Symptom)

Applying a 20% discount to Alice’s cart also silently changes Bob’s brand-new cart price because both share nested template references.

Expected Behavior

  • `DEFAULT_TEMPLATE` remains untouched (`basePrice: 1000, meta.discountApplied: false`).
  • `applyDiscount(cart, 20)` returns a brand-new immutable cart object without mutating `cart`.
  • Two carts created from `createCart()` are completely isolated in top-level and nested properties.

Debugging Hints (0/2 used)

Try spotting the bug in the editor first. Need a nudge? Reveal Hint 1 anytime.

Root Cause Breakdown

Pass all 3 automated verification checks on the right to unlock the full Root Cause explanation.

Automated Bug Verification

3 Checks Ready
  • DEFAULT_TEMPLATE stays pure after creating and discounting cartsBase price and discountApplied must stay unchanged.
  • applyDiscount does not mutate the input cart objectOriginal cart stays 1000 while returned cart becomes 800.
  • Two carts stay isolated in nested items & metaBob receives fresh defaults after Alice applies discount.
bugfix.js
Live Sandboxed PreviewCtrl + Enter to verify
Console Output0 log(s)
No console output yet. Run Preview or Verify Bug Fix.