const isValid = function(s) {
let stack = [];
let obj = {
'[': ']',
'{': '}',
'(': ')'
};
for (let i = 0; i < s.length; i++) {
if (s[i] === "[" || s[i] === '{' || s[i] === '(') {
stack.push(s[i]);
} else {
let key = stack.pop();
if (obj[key] !== s[i]) {
return false;
}
}
}
return stack.length === 0;
}