function selectSort(nums){ let len = nums.length; let min,temp; for (let i=0;i<len-1;i++){ let k=i; for (let j=i+1;j<len;j++){ if (nums[k]>nums[j]){ k=j; } } min = nums[i]; nums[i] = nums[k]; nums[k] = min; } return nums; } console.log(selectSort([1, 5, 3, 4, 6, 12, 3])); // 每一轮选择出最小值的索引,并替换到前面去