选择排序
2021-03-27 15:28
标签:div length log 选择 let sele return data code 选择排序 标签:div length log 选择 let sele return data code 原文地址:https://www.cnblogs.com/jiajiaobj/p/13654940.htmlconst arr = [21, 2, 5, 3, 1, 2, 6, 3, 3];
function select(data) {
var index;
for (let i = 0; i ) {
index = i;
for (let m = i; m ) {
if (data[index] > data[m]) {
index = m;
}
}
let tmp = data[index];
data[index] = data[i];
data[i] = tmp;
}
return data;
}
console.log(select(arr));