sorting numeric values in a js array…

Just a reminder that when using sort on a javascript array, if trying to sort numeric values: arr.sort() will sort using unicode point order. Meaning that this: [2, 10, 1, 21].sort(); will be: [1, 10, 2, 21]

If you want to sort an array of numeric values properly, you can now use: [2, 10, 1, 21].sort((a,b) => (a-b)); which will be: [1, 2, 10, 21]

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.