If the element exists, return the index.

If it isn't, then remember the array is sorted: so if you added the value 4 to an array containing 1, 3, and 5 you would get 1, 3, 4, 5.

The index of the number you inserted would be 2 - so you return that.

Basically, return the index of the first number that is greater than or equal to the number you are looking for, or the length if you run out of elements to compare.

15,029,039 members