function binarySearch(array, key, comparator) {
    return binarySearch2(array.length, i => comparator(array[i], key));
}
Performs a binary search algorithm over a sorted array.

@param array The array being searched.
@param key The value we search for.
@param comparator A function that takes two array elements and returns zero
  if they are equal, a negative number if the first element precedes the
  second one in the sorting order, or a positive number if the second element
  precedes the first one.
@return See {@link binarySearch2}