数组排序-基础数据类型排序
let arr = [1, 9, 3, 4, 5, 8, 2, 6, 7];
// // 排序
function paixu(arr) {
let o = JSON.parse(JSON.stringify(arr));
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i; j++) {
let el0 = o[j];
let el1 = o[j + 1];
// 当前项 大于 当前前项
if (el0 > el1) {
// 我就将 当前项 与当前前项 互换位置
let cy = o[j + 1];
o[j + 1] = o[j];
o[j] = cy;
}
}
}
return o;
}
console.log(paixu(arr));