Duplicate braces

by Alex Myronov

JavaScript

function findDuplicates(str) {
  const tokens = str.split('')
  const stack = []
  
  for (let i = 0; i < tokens.length; i++) {
		console.log(tokens[i])
    if (tokens[i] === ')') {
    	
       if (stack[stack.length - 1] === '(') {
          return true
       }

			 while (stack[stack.length - 1] !== '(') {
       	stack.pop()
       }

    } else {
    	stack.push(tokens[i])
    }
  }

  return stack
}

console.log('duplicates', findDuplicates('(((x))+y)+z'))