code: function findIdx(table, val) {
      if (table[0] > val)
          return -1;
  
      var l = 0, r = table.length;
      while (l < r-1) { // always table[l] <= val < table[r]
          var mid = l + Math.floor((r-l+1)/2);
          if (table[mid] <= val)
              l = mid;
          else
              r = mid;
      }
      return l;
  }
docs: Binary search for GB18030. Returns largest i such that table[i] <= val.