title: Valid Parenthesis Troubleshooting
body: <p>I'm working on a coding challenge that involves valid parenthesis and I'm trying to troubleshoot why it's not giving me the intended response.</p>
  <pre><code> function isValid(str) {
  
    if (str.length === 0)
      return true
  
    let matchingOpeningBracket, char
    let stack = []
  
    let openingBrackets = ['[', '&lt;', '(']
    let closingBrackets = [']', '&gt;', ')']
  
    for (let i = 0; i &lt; str.length; i++) {
      char = str[i]
  
      if (closingBrackets.indexOf(char) &gt; -1) {
        matchingOpeningBracket = openingBrackets[closingBrackets.indexOf(char)]
        if (stack.length == 0 || (stack.pop() != matchingOpeningBracket)) {
          return false
        }
      } else {
        stack.push(char)
      }
    }
  
    return (stack.length == 0)
  };
  </code></pre>
  <p>When I try to check console.log(isValid('---(++++)---')) and console.log(isValid('before(middle[])after')) it gives me a false value but it should be passing as true according to the challenge key. I'm not sure what step I'm missing. The other tests examples are logging as intended as seen here except for the first 2.</p>
  <pre><code>//true // returns false
  // let example1 = (&quot;before(middle[])after&quot;)
  //true //returns false
  // let example1 = (&quot;---(++++)---&quot;)
  //true 
  // let example1 = (&quot;&quot;)
  //false 
  // let example1 = (&quot;)(&quot;)
  //false
  // let example1 = (&quot;&lt;(&gt;)&quot;)
  //true 
  // let example1 = (&quot;([&lt;&gt;()])&quot;)
  //false
  // let example1 = (&quot;([)&quot;)
  </code></pre>