Created
June 8, 2016 10:53
-
-
Save Schwad/d6f891b0753e1141dc6a6400bd1f2c14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def matching_brackets?(arg) | |
opener_symbols = ["{", "(", "["] | |
closer_symbols = ["}", ")", "]"] | |
openers = Hash.new(0) | |
closers = Hash.new(0) | |
openers['('] = arg.scan(/\(/).length | |
openers['['] = arg.scan(/\[/).length | |
openers['{'] = arg.scan(/\{/).length | |
closers[')'] = arg.scan(/\)/).length | |
closers[']'] = arg.scan(/\]/).length | |
closers['}'] = arg.scan(/\}/).length | |
if openers['('] != closers[')'] | |
return false | |
end | |
if openers['{'] != closers['}'] | |
return false | |
end | |
if openers['['] != closers[']'] | |
return false | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment