let isValid =function(str){
let stack =[];
let len = str.length;if(len <2)return false;for(let elem of str){switch(elem){case"{":case"[":case"(":
stack.push(elem);break;case"(":if(stack.pop()!==")")return false;break;case"[":if(stack.pop()!=="]")return false;break;case"}":if(stack.pop()!=="{")return false;break;}}return!stack.length
}
console.log(isValid("{}"))
let isValid =function(str){
let len = str.length
if(len%2!==0)return false
let map =new Map([['{','}'],['(',')'],['[',']']])
let stack =[];for(elem of str){if(map.has(elem)){
stack.push(elem)}else{if(map.get(stack[stack.length-1])!== elem || stack.length ==0){return false
}else{
stack.pop()}}}return!stack.length
};
console.log(isValid("{[}"));