Edit the code in the box below, or replace it with any code you like.
const hasBalancedBrackets = (str) => {
str = str.replace(/;.*/, '')
const stack = []
const map = {
'(': ')',
'[': ']',
'{': '}',
}
let isInQuote = false
for (let i = 0; i < str.length; i++) {
const char = str[i]
if (char === '"' && str[i - 1] !== '\\') isInQuote = !isInQuote
if (char in map && !isInQuote) stack.push(char)
else if (Object.values(map).indexOf(char) > -1 && !isInQuote) {
if (char === map[stack.slice(-1)]) stack.pop()
else return false
}
}
return stack.length !== 0 ? false : true
}