Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def syntax_checker(string)
- split_arr = string.split("")
- length = split_arr.size
- return false if length <= 1
- return false if length.odd?
- mirror = []
- split_arr[length/2..length-1].each do |c|
- if c == "]"
- mirror << "["
- end
- if c == "}"
- mirror << "{"
- end
- if c == ")"
- mirror << "("
- end
- end
- p mirror
- split_arr[0..length/2 - 1] == mirror.reverse
- end
- def syntax_checker(string)
- split_arr = string.split("")
- length = split_arr.size
- return false if length <= 1
- return false if length.odd?
- last_char = []
- hash = {}
- split_arr.each do |char|
- if char == '[' || char == ']'
- hash[:square] += 1
- open = true
- elsif char == '{' || char == '}'
- hash[:curly] += 1
- open = true
- elsif char == '(' || char == ')'
- hash[:round] += 1
- end
- last_char = char
- end
- p hash
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement