You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 颠倒排序varx=[1,3,2];vary=x.sort((a,b)=>{// if (a < b ) {// return -1;// }// if (a > b ) {// return 1;// }// // a must be equal to b// return 0;// 以上可以简写如下returna-b;});console.log(y)// [1, 2, 3]
Activity
vkboo commentedon Sep 22, 2019
reverse()
直接颠倒数组中的元素sort()
自定义排序,基础是按照字符编码(Unicode->UTF-16)进行排序(数组在原数组上进行排序,不生成副本)for
循环xiaoqiangz commentedon Jul 26, 2022
sort((a,b)=> return a - b )