-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
从数组的开头开始,将第一个元素和其他元素比较,最小的元素会被放到数组第一个位置,再从第二个位置继续。
const selectionStor = arr => {
let temp,
min,
len = arr.length;
for(let i = 0; i < len -1; i ++){
min = i;
for(let j = i+1; j < len ; j ++){
if(arr[j]<arr[min]){
min = j;
}
}
temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
return arr;
}
console.log(selectionStor([1,4,3,5,9,7,3,3,5,3,2]))