编辑代码

function quickSort(arr) {
    if(arr.length <= 1) return arr;
    const base = arr[0];
    let left = [], right = [];
    for(let i = 1, len = arr.length; i < len; i++) {
        const item = arr[i]
        if(item < base ) {
            left.push(item)
        } else {
            right.push(item)
        }
    }
    return [...quickSort(left), base, ...quickSort(right)]
}
function bucketSort(arr, bucketSize = 5) {
    const len = arr.length;
    if (len < 2) return arr;
    const minVal = Math.min(...arr), maxVal = Math.max(...arr);
    const bucketCount = Math.floor((maxVal - minVal) / bucketSize) + 1;
    const bucketList = new Array(bucketCount).fill(0).map(item => ([]));
    console.log(bucketList)
    for (let a of arr) {
        const bkId = Math.floor((a - minVal) / bucketSize)
        console.log(bkId)
        bucketList[bkId].push(a)
    }
    return bucketList.flatMap(item => quickSort(item))
}
const arr = [1, 6, 9, 10, 12]
const res = bucketSort(arr)
console.log(res)