arr.sort((x, y) => {
if(x > y){
return 1
}
else if(x < y){
return -1
else{
return 0
});
console.log(arr); // [1, 2, 10, 20]
Sign in to make a reply
落叶起声
arr.sort((x, y) => {
if(x > y){
return 1
}
else if(x < y){
return -1
}
else{
return 0
}
});
console.log(arr); // [1, 2, 10, 20]