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}

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

1. The invitation code is [460 233 021].Copy

Jest test example.

How does Vue.js compare against ReactJS and Angular in runtime performance?

Walking Inside the Node.js Event Loop

A Web3-redux-react-starter-kit Walkthrough

Play 2[Scala], React.js,GraphQL- Part 1

JOIN OUR VIP LIST

7 Best Practices for React Native Applications

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
Aidanmc

Aidanmc

More from Medium

Byte size info: Stack data Structures

Doubly Linked List Implementation using JavaScript

Polyfills, updates, webpack, node.js: pain.

Yarn 2(Berry)-3 significant additions