Intern — Senior
Validation of the correct placement of round brackets in a string
livecode
Task condition
Implement a function that takes a string and determines whether the parentheses ( and ) are correctly placed in it. The function should return true if each opening parenthesis has a corresponding closing one and the nesting order is correct, and false otherwise.
function validateParentheses(str: string): boolean {
// implementation
}
// validateParentheses('(') === false
// validateParentheses(')') === false
// validateParentheses('()') === true
// validateParentheses('(())') === true
// validateParentheses(')(') === false
// validateParentheses(')()(') === false