Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jimishjoban/adb19f0b71a3b8dffdcd49bb640577c0 to your computer and use it in GitHub Desktop.
Save jimishjoban/adb19f0b71a3b8dffdcd49bb640577c0 to your computer and use it in GitHub Desktop.
coding fun
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