编辑代码

// 有效的括号

const str1 = '(({{}]]])()[]';

const stack = [];
const map = new Map();

map.set('(', ')');
map.set('[', ']');
map.set('{', '}');

for (let i = 0;i < str1.length; i++) {
    if (map.has(str1[i])) {
        stack.push(str1[i])
    } else {
        const temp = stack[stack.length - 1];
        console.log('temp---------》》》:', temp);
    }
}

console.log('stack---------》》:',stack);
console.log('map-----------》》:', map);