All 35 Bugs /
0/35 Fixed ✓
JavaScriptEasy~8 min

Array.sort() Mutating Input & String Ordering Trap

What's Broken (Symptom)

Sorting prices `[100, 20, 5]` returns `[100, 20, 5]` lexicographically AND unexpectedly mutates the original source array in place.

Expected Behavior

  • • Clone first (`[...nums]` or `nums.toSorted(...)`) and pass numeric comparator `(a, b) => a - b`.

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 1 automated verification checks on the right to unlock the full Root Cause explanation.

Automated Bug Verification

1 Checks Ready
  • Sorts numbers numerically [5, 20, 100]Does not treat 100 as smaller than 20.
bugfix.js
Live Sandboxed PreviewCtrl + Enter to verify
Console Output0 log(s)
No console output yet. Run Preview or Verify Bug Fix.