binary loop search

We use a loop to do binary search on a sorted array.

We start with two markers, one on each end: start and end.
We then calculate mid. We compare the value at index mid to the value we’re trying to insert.

If our to insert value is larger, we move our start to mid + 1.
If our to insert value is smaller, we move our end to mid – 1.

This way, we squeeze our start and end markers tighter and tighter.

Once we squeeze where start <= end is false (AKA start > end )…our mid is at the correct index. All we need to do is see if our to insert value is larger or smaller than the value at index mid.

If larger, arr.splice(mid+1, 0)
If smaller, arr.splice(mid, 0)

Because by default splice at an index will add the value at that index and push everything down.