Content model:
- If the element has a label attribute and a value attribute: Nothing.
- If the element has a label attribute but no value attribute: Text.
- If the element has no label attribute: and is not a child of a datalist element: Text that is not inter-element white space.
- If the element has no label attribute and is a child of a datalist element: Text.
function check(str, bracketsConfig) {
let bconf = bracketsConfig.reduce(
(acc, val) => {
acc[val[0]] = val[1];
acc[val[1]] = null;
return acc;
},
{}
);
let stack = [];
for (let i = 0; i < str.length; i++) {
let char = str[i];
if (bconf[char] === null) {
if (stack.pop() !== char) {
return false;
}
} else if (bconf[char] !== undefined) {
stack.push(bconf[char]);
}
}
if (stack.length !== 0) {
return false;
}
return true;
}