sort() sorts the array and replaces the original array elements. But how is it implemented? Is it through bubbling? Quick sort or some other sorting method? Ask for advice~
[9, 3, 4, 6, 1, 2, 8, 7].sort(function(x, y) {
return x - y;
})
Result: [1, 2, 3, 4, 6, 7, 8, 9]
————————————————————————————
[9, 3, 4, 6, 1, 2, 8, 7].sort(function(x, y) {
return y-x;
})
Result: [9, 8, 7, 6, 4, 3, 2, 1]
怪我咯2017-06-12 09:24:48
Different browser implementations may be different, and the sorting method may also be different depending on the number of array elements. I remember there is an article about this, search it first and then ask