Fix numeric sort in `sortScores`

easy
By FrontendAtlas Editorial · Updated Oct 5, 2026
A teammate wrote a tiny leaderboard helper with plain sort(). It looked fine in a quick demo with single-digit values, then broke the moment scores like 10 and 100 showed up. Fix the bug so numbers sort numerically in ascending order while keeping the original input unchanged.

Solution idea

export default function sortScores(scores){

return scores.slice().sort((a, b) => a - b);

}

Examples
sortScores([10, 2, 30, 4]) // [2, 4, 10, 30]

sortScores([1, 100, 20, 3]) // [1, 3, 20, 100]