Sort prices without mutation
Take your time, follow the code and check your understanding.
The codeAPI transformations
Example checks
INPUT
[
{
"price": 10
},
{
"price": 2
}
]EXPECTED[
{
"price": 2
},
{
"price": 10
}
]INPUT
[]EXPECTED
[]
Your answer5 min · no timer
Implement solve(rows) and return a value. The example checks are visible. JavaScript runs in an isolated, network-blocked worker with a 2-second limit.
Show solution and explanation
Copy before sort because sort changes its array.
function solve(rows) {
return [...rows].sort((a, b) => a.price - b.price);
}