code: function binarySearch(array, func) {
      // min is inclusive, max exclusive.
      let min = 0,
          max = array.length;
  
      while (min < max) {
          const mid = (min + max) >> 1;
          const res = func(array[mid]);
          if (res > 0) {
              // the element at 'mid' is too big; set it as the new max.
              max = mid;
          } else {
              // the element at 'mid' is too small. 'min' is inclusive, so +1.
              min = mid + 1;
          }
      }
      // presumably, min==max now.
      return min;
  }
docs: /* search in a sorted array.
  
  returns the index of the last element for which func returns
  greater than zero, or array.length if no such element exists.