Intern — Middle
Validation of correct placement of different types of brackets
livecode
Task condition
The task is to implement a function that determines whether three types of brackets are correctly placed in a string:
- Round — ()
- Square — []
- Curly — {}
The function should return
trueif all brackets are opened and closed in the correct order and nested according to pairing rules, otherwise —false.
function checkBrackets(str: string): boolean {
// code
}
// checkBrackets('(') === false
// checkBrackets(')') === true
// checkBrackets('[]') === false
// checkBrackets('[()]') === true
// checkBrackets('()[{}])' === true
// checkBrackets('(){[}') === false