Validate parentheses "()" and "[]" are balanced Firstly I was using regex to get if the number of parentheses in a string is balanced or not, but the performance was quite slow when any large string was passed to the regex. So I created this custom method, which returns whether a string contains balanced parentheses or not. Please review this code and point out any mistakes and improvements.

checkBalancedBrackets(str) {
    var b1 = [];
    var b2 = [];
    for ( var i=0; i &lt; str.length; i++ ) {
        var ch = str.charAt(i);
        if (ch == "(" ) b1.push(ch);
        else if ( ch == "[" ) b2.push(ch);
        else if ( ch == ")" ) {
            if (b1.length &lt; 1) {
                return false;
            } else {
                b1.pop();
            }
        }
        else if ( ch == "]" ) {
            if (b2.length &lt; 1) {
                return false;
            } else {
                b2.pop();
            }
        }
    }
    return b1.length == 0 &amp;&amp; b2.length == 0;
}
A short review;


checkBalancedBrackets("([)]") returns true, not sure that was the intention
b1 and b2 are not great names, what does the b stand for?
Using arrays is not needed, all the code does is counting numbers, you can just use numbers
The inconsistent use of curly braces in your if and else if clauses is not good