封装排序方法
- 对象排序方法
function compare(arr,styleName){
arr.sort((a,b)=>{
let x=a[styleName];
let y=b[styleName];
return x-y;
})
}
- 数组排序方法
function compare(a,b){
return a-b;
}
function compare(arr,styleName){
arr.sort((a,b)=>{
let x=a[styleName];
let y=b[styleName];
return x-y;
})
}
function compare(a,b){
return a-b;
}