Open this example in the interactive library
Source code
const scores = [10, 2, 30, 1];
console.log([...scores].sort((a, b) => a - b));
console.log(scores);
Sample output
[ 1, 2, 10, 30 ] [ 10, 2, 30, 1 ]

Sort numbers numerically. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const scores = [10, 2, 30, 1];
console.log([...scores].sort((a, b) => a - b));
console.log(scores);
[ 1, 2, 10, 30 ] [ 10, 2, 30, 1 ]