标签:tar splice 快速 quic func length const 排序 concat
function quickSort(arr = [3, 7, 20, 1, 10, 6, 15, 5, 12]) {
if (arr.length <= 1) return arr
const leftArr,rightArr = [],
let current = null
current = arr.splice(0, 1)
for (let i = 0; i < arr.length; i++) {
arr[i] < current ? leftArr.push(arr[i]) : rightArr.push(arr[i])
}
return quickSort(leftArr).concat(current, quickSort(rightArr))
}
js之快速排序算法
标签:tar splice 快速 quic func length const 排序 concat
原文地址:https://www.cnblogs.com/rrrjc/p/11258632.html