code: function findTokenIndex(tokens, offset) {
    var min = 0;
    var max = tokens.length - 1;
  
    while (min <= max) {
      var ptr = (min + max) / 2 | 0;
      var token = tokens[ptr];
      if (token.end <= offset) {
        min = ptr + 1;
      } else if (token.start > offset) {
        max = ptr - 1;
      } else {
        return ptr;
      }
    }
  
    return ptr;
  }
docs: Given an array of sorted tokens, find the index of the token which contains the given offset. Uses binary search for O(log N) performance.