function selsetSort(arr) {
const len = arr.length
if (len <= 1) return arr
for (let i = 0; i < len - 1; ++i) {
let index = i
let j = i + 1
for (; j < len; ++j) {
if (arr[j] < arr[index]) {
index = j
}
}
let tmp = arr[i]
arr[i] = arr[index]
arr[index] = tmp
}
return arr
}
网友评论