const str = '({[]})[';
const pairs = {
')' : '(',
'}' : '{',
']' : '['
}
function isValid(str){
const stack =[];
for (let s of str) {
if(s == '(' || s == '{' || s == '['){
stack.push(s);
} else{
console.log(s, pairs[s])
if(pairs[s] !== stack.pop() ){
return false;
}
}
}
return stack.length == 0
}
const result = isValid(str);
console.log(result)
To embed this project on your website, copy the following code and paste it into your website's HTML: