1.伪数组
var fack = {
0:'a',
1:'b',
2:'c',
length: 3
}
var arr = [].slice.call(fack)
console.log(arr)
1.比较函数 a - b 是升序排列,b - a 是降序
const arr = [49, 5, 14, 89, 71, 3, 10];
console.log(arr);
let times = 0;
let res = [];
arr.sort((a, b) => {
res.push({times, a, b, "a - b": a - b});
times++;
return a - b;
});
console.log(res);
console.log(arr);
//需要记住 return a - b 是升序排列,return b - a 是降序排列即可
arr.sort((a,b) => {
const res = a - b;
return res > 0 ? 1 : (res < 0 ? -1 : 0 );
});