The function below mutates its input array — a classic source of bugs.
// dirty — mutates the original array!
function solve(cart, item) {
cart.push(item);
cart.sort((a, b) => a.price - b.price);
return cart;
}Refactor `solve(cart, item)` so it returns a new sorted array without modifying cart.
After calling solve(cart, item), the original cart array must be unchanged.
Sample tests