Implement arrayBalancedBrackets(str) — return whether the brackets in str are properly opened and closed in the correct order. This is the classic Valid Parentheses problem, extended to three bracket types: (), [], and {}. A string is balanced when every opener has a matching closer of the same type, every closer appears in the right order, and nothing is left open at the end. Any character that isn't a bracket is ignored, so it works on real code-like strings.
// str: string — a string that may contain (), [], {} and any other characters.
// returns: boolean
// true if every bracket is matched and correctly nested; false otherwise.
function arrayBalancedBrackets(str): boolean;
// A nested mix of all three types, each closed in the right order.
arrayBalancedBrackets('([]{})');
// → true
// The ) closes before the [ does — the nesting crosses over.
arrayBalancedBrackets('([)]');
// → false
( can only be closed by a ), never by a ] or }. So '(]' is not balanced.'([)]' is false because the ( is still open when ) arrives.'(((' is false; '' (no brackets at all) is true.')', is not balanced.'a(b)c' is true — only the brackets are checked.