title: How to check the sequence of opening and closing brackets in string?
body: <p>Need to find open and closed bracket, if the sequence of opening and closing brackets is violated, then return false.</p>
  
  <p>But if don't revert right array to compare with left array, i don't make check brackets here <code>{[(3+1)+2]+}</code>. And if reverse like now, then i fail to check here <code>[1+1]+(2*2)-{3/3}</code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function brackets(expression){
      let leftArr=[];
      let rightArr = [];
      for(let i=0; i&lt;expression.length; i++){
        if(expression[i] === '(' || expression[i] === '[' || expression[i] === "{"){
           leftArr.push(expression[i]);
          }
          
          
          if(expression[i] === ')'){
        
            rightArr.push("(");
          }else if(expression[i] === '}'){
          
            rightArr.push("{");
          } else if(expression[i] === ']'){
          
            rightArr.push("[");
          }
     }
    
     rightArr.reverse();
      
      if(leftArr.length&lt;rightArr.length || leftArr.length&gt;rightArr.length){
      return false;
      }
      
      for(let k=0; k&lt;leftArr.length; k++) {
        if(leftArr[k] != rightArr[k]){
            return false;
          }
      }
  
      return true;
  }
  
  
  
  console.log(brackets('(3+{1-1)}')); // false
  console.log(brackets('{[(3+1)+2]+}')); //true
  console.log(brackets('[1+1]+(2*2)-{3/3}')); //true
  console.log(brackets('(({[(((1)-2)+3)-3]/3}-3)')); //false</code></pre>
  </div>
  </div>
  </p>