Debugging

Fix Mutation Bug

mediumdebuggingimmutabilityarray
0:00

Problem

`addItem` should return a NEW array with the item appended, not mutate the input. Fix it so the original array is unchanged and the returned array contains the new item.

Your solution
Test results
Click Run tests to check your solution against the test cases.

About this challenge

Fix Mutation Bug is a medium debugging coding challenge. It tests your ability to read unfamiliar code, find the defect, and fix it without breaking the rest. Write your solution in the editor above, run it against the test cases, and get instant feedback — free, in your browser, no sign-up.

Show a hint & approach (spoiler)

Hint: Return a new array with the spread operator: `return [...arr, item]`.

Keep practicing

Browse all coding challenges, or build intuition for the underlying concepts with the algorithm visualizers and the developer cheatsheets.