Меню

const qsort = (arr) => {
    if (arr.length < 2) {
        return arr
    }
    const pivotIndex = Math.floor(Math.random() * arr.length),
        pivot = arr[pivotIndex],
        less = [],
        greater = []
    for (let i = 0; i < arr.length; i++) {
        const isPivotIndex = i === pivotIndex
        if (arr[i] < pivot) {
            less.push(arr[i])
        } else if (arr[i] >= pivot && !isPivotIndex) {
            greater.push(arr[i])
        }
    }
    return [...qsort(less), pivot, ...qsort(greater)]
}