title: JS function for validation of the brackets in a string
body: <p>guys! I want to ask you how can a make a function, that checks if the brackets in a string are put correctly. For example "(a + b).4,2 - )c + 5)" and I have to check the brackets. I tried something, but it doesn't seem to work(sorry, I'm a newbie in javascript):</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function checkBrackets(str){
   var newOrder = [];
   var bracket1 = "(";
   var bracket2 = ")";
   for(var bracket1 in str){
    
     newOrder.push("1");
   }
  
   for(bracket2 in str){
    
     newOrder.pop();
   }
  
   if(newOrder.length == 0){
    console.log("Right!" + newOrder);
   } else{
    console.log("Wrong!" + newOrder);
   }
  }
  
  checkBrackets('( ( a + b ) / 5 – d )');</code></pre>
  </div>
  </div>
  </p>
  
  <p>I tried to loop through the string with a for-in loop and whenever it hits a "(" to add "1" to the array. And when it hits a ")" to remove one "1" from the array. At the end if the array is empty, i could conclude, that the brackets were put correctly and if not, they weren't.</p>