let arr =['A', 'U', 'B', 'R', 'S'];
let U = [];
let A = [];
let S = [];
for (let i=0;i<arr.length;i++){
switch (arr[i]){
case 'U':
U.push(arr[i]);
break;
case 'A':
A.push(arr[i]);
break;
case 'S':
S.push(arr[i]);
break;
}
}
let newArr = U.concat(A).concat(S);
console.log(newArr)
//['U','A','S']
网友评论