正文比sort()性能更好的原生js代码实现数组从小到大排序IP云V管理员/2022-11-30/3 阅读 11/30提示:扫一扫查出行【扫一扫了解最新限行尾号】复制提示 nums = [1,2,4,1,34,6,-1,2] for(let i = nums.length - 1; i > 0; i--) { let maxIdx = i; for(let j = 0; j < i; j++) { if(nums[maxIdx] < nums[j]) maxIdx = j; } if(maxIdx !== i) { let temp = nums[maxIdx]; nums[maxIdx] = nums[i]; nums[i] = temp; } }