记录 Js 二维数组的排序
二维数组
let schedule=[[33, 38], [90, 92], [87, 88], [98, 100], [20, 32]]
冒泡排序(升序)
var num
for (let i = 0; i < schedule.length; i++) {
for (let j = 0; j < schedule.length - 1; j++) {
if (schedule[j][1] > schedule[j + 1][1]) {
num = schedule[j];
schedule[j] = schedule[j + 1];
schedule[j + 1] = num;
}
}
}
Js sort()方法(升序)
schedule.sort((arr1, arr2) => {
return arr1[0] - arr2[0];
});