Created
July 11, 2019 11:22
-
-
Save jimishjoban/adb19f0b71a3b8dffdcd49bb640577c0 to your computer and use it in GitHub Desktop.
coding fun
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 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment