main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
let checkmatch=(a,b)=>{
  if( (a == '(' && b == ')') ||    (a == '[' && b == ']') || (a == '{' && b == '}') )
  {return true}
  return false
}

let check=(input)=>{
  let stack=[]
  for(i=0;i<input.length;i++)
  {
    console.log(stack)
    if(stack.length > 0 && checkmatch(stack[stack.length-1],input[i]))
    {
        stack.pop()
    }
    else{
      stack.push(input[i])
    }
  }
  if(stack.length == 0){return true}
  return false
}

console.log(check('({[]})'));
console.log(check('(({[]{]}))'));
console.log(check('([])'));
console.log(check('([)]'));
console.log(check('[(){}]'));//5
console.log(check('((()))'));//6
console.log(check('([[]]'));//7
console.log(check('[]]'));//8
console.log(check('(){}'));//9
Native Browser JavaScript