code: function getMatchingParenthesis(string, startPos) {
      var length = string.length;
      var bracket = 1;
      for (var i=startPos+1; i<=length; i++) {
          if (string[i] == '(') {
              bracket += 1;
          } else if (string[i] == ')') {
              bracket -= 1;
          }
          if (bracket == 0) {
              return i;
          }
      }
  }
docs: Find the position of a matching closing bracket for a string opening bracket