SOURCE

const quickSort = function (arr, left = 0, right = arr.length - 1) {
    if (left >= right) return
    const start = left, end = right
    const pivot = arr[left]
    while (left < right) {
        while (left < right && arr[right] >= pivot) {
            right--
        }
        if (left < right) {
            arr[left] = arr[right]
        }
        while (left < right && arr[left] <= pivot) {
            left++
        }
        if (left < right) {
            arr[right] = arr[left]
        }
    }
    arr[left] = pivot
    quickSort(arr, start, left - 1)
    quickSort(arr, left + 1, end)
    return arr
}

console.log(quickSort([3,2,1,4,1,1]))
console 命令行工具 X clear

                    
>
console