code: function binarySearch(arr, pred) {
      let begin   = -1;
      let end     = arr.length;
  
      while (1 + begin < end) {
          const mi = begin + ((end - begin) >> 1);
  
          if (pred(arr[mi]))
              end = mi;
          else
              begin = mi;
      }
  
      return end;
  }
docs: ///////////////////////////////////////////////////// this code borrowed from stackoverflow: https://stackoverflow.com/questions/22697936/binary-search-in-javascript