const n = [2, 5, 100, 4]
n.sort((a, b) => {
console.log(a, b)
return a - b;
})
// console log
5 2
100 5
4 100
Why is a
5
and b
2
, etc..?
In this question which asks a similar question.
Answers given amount to: "Browsers interpret the spec, therefore the order is not guaranteed". But fails to answer the question.