V School | Better Humans, Better Outcomes

Better Humans, Better Outcomes

Balance Parentheses

Given a string including parentheses, write a function that returns true if every opening parentheses has a closing parentheses. Example function balanceParentheses(str){ // Your code here } balanceParentheses("()()") // Output: true balanceParentheses("(())") // Output: true balanceParentheses("()))") // Output: false Also, every closing parentheses needs an opening partner before it. balanceParentheses(")()(") // Output: false balanceParentheses("())(") // Output: