for (let i = 0; i < array.length; i++) {
const item = array[i];
if ((typeof item) == ‘number’) {
if (numResult.length == 0) {
numResult.push(item);
continue;
}
for (let j = 0; j < numResult.length; j++) {
if (item <= numResult[j]) {
numResult.splice(j, 0, item);
break;
} else {
if (j == (numResult.length - 1)) {
numResult.push(item);
break;
}
}
}
} else {
if (strResult.length == 0) {
strResult.push(item);
continue;
}
for (let j = 0; j < strResult.length; j++) {
if (item.length <= strResult[j].length) {
strResult.splice(j, 0, item);
break;
} else {
if (j == (strResult.length - 1)) {
strResult.push(item);
break;
}
}
}
}
}
对数组中的字符串 和数字排序
最新推荐文章于 2023-02-28 18:00:58 发布