#177
Balancing Brackets
 

Difficulty:Medium
Topics:parsing


When parsing a snippet of code it's often a good idea to do a sanity check to see if all the brackets match up. Write a function that takes in a string and returns truthy if all square [ ] round ( ) and curly { } brackets are properly paired and legally nested, or returns falsey otherwise.
test not run
(__ "This string has no brackets.")
test not run
(__ "class Test {
                          public static void main(String[] args) {
                            System.out.println(\"Hello world.\");
                          }
                        }")
test not run
(not (__ "(start, end]"))
test not run
(not (__ "())"))
test not run
(not (__ "[ { ] } "))
test not run
(__ "([]([(()){()}(()(()))(([[]]({}()))())]((((()()))))))")
test not run
(not (__ "([]([(()){()}(()(()))(([[]]({}([)))())]((((()()))))))"))
test not run
(not (__ "["))


Code which fills in the blank: