const parentheses = ['(', ')', '{', '}', '[', ']'];
const isValid = array => {
const stack = [];
const bracketsMap = {
')': '(',
'}': '{',
']': '['
};
for (let i=0; i < array.length; i++) {
if (array[i] === '(' || array[i] === '{' || array[i] === '[') {
stack.push(array[i]);
} else if (stack[stack.length - 1] === bracketsMap[array[i]]) {
stack.pop();
} else return false
}
return stack.length ? false : true;
};
console.log(isValid(parentheses));