算法

快排

export  default function quickSort(arr) {
    if(!arr.length) {
        return [];
    } else {
        let [pivot, ...rest] = arr;
        return [
            ...quickSort(rest.filter(e => e <= pivot)),
            pivot,
            ...quickSort(rest.filter(e => e > pivot))
        ]
    }
}

二分查找

function binarySearch(arr, value, start=0, end) {
    if (!arr.length) {
        return -1;
    } else {
        let middle = ((start + end || arr.length) / 2)|0;
        if (arr[middle] > value) {
            return binarySearch(arr, value, start, middle - 1)
        }
        if (arr[middle] < value) {
            return binarySearch(arr, value, middle + 1, end)
        }
        return middle;
    }
}