Sobes.tech
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:

  1. Round — ()
  2. Square — []
  3. Curly — {} The function should return true if 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