Speed Searching with Binary

function binarySearch(arr) {    let low = 0;    let high = arr.length - 1;    while (low <= high) {        let mid = Math.floor((high + low) / 2);        if (arr[mid] === 10) {            return mid;        } else if (arr[mid] < 10) {            low = mid + 1;        } else {            high = mid - 1;        }    }    return -1}
function binarySearchFirst(arr, num) {    let first = -1    let low = 0;    let high = arr.length - 1;    while (low <= high) {        let mid = Math.floor(low + (high - low) / 2);        if (arr[mid] >= num) {            first = mid            high = mid - 1        } else {            low = mid + 1;        }    }    return first}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store