SOURCE

const arr = [3,2,5,1,8,3,9,11,1];

function quickSort(arr) {
    if(arr.length < 2) return arr;
    return partition(arr)
}


function partition(arr) {
    if(arr.length < 2) return arr;
    const pivot = arr[0]
    arr.shift();
    const left = [];
    const right = []
    for(let i = 0;i < arr.length;i++){
        if(arr[i] <= pivot){
            left.push(arr[i])
        }else{
            right.push(arr[i])
        }
    }

    return [...partition(left),pivot,...partition(right)]
    

}
console 命令行工具 X clear

                    
>
console