// 判断标签是否闭合
function isCloseed(params, keyCollection = [['{','}'],['[',']'],['(',')'],['<','>']]) {
const array = params.split('');
// 过滤掉不符合要求的单括号
keyCollection = keyCollection.filter(item=> Array.isArray(item) && item.length === 2)
if (!array.length || !keyCollection.length) return
const keyObj = {}
const stack = []
const leftKey = []
const rightKey = []
for (let i = 0; i < keyCollection.length; i++) {
const [left,right] = keyCollection[i];
let courrentIndex = i
keyObj[left] = courrentIndex + 1
keyObj[right] = -(courrentIndex + 1)
leftKey.push(left)
rightKey.push(right)
}
for (let index = 0; index < array.length; index++) {
const element = array[index];
if(keyObj.hasOwnProperty(element) && leftKey.includes(element)) {
stack.push(keyObj[element])
}else if(keyObj.hasOwnProperty(element) && rightKey.includes(element)) {
const currentKeyObj = keyObj[element]
const currentLength = stack.length
if(currentLength>0 && stack[currentLength -1] + currentKeyObj === 0) {
stack.pop()
} else {
stack.push(currentKeyObj)
}
}
}
return stack.length === 0
}
isCloseed('{{}[()]}<>') // true