Created
October 17, 2020 20:10
-
-
Save kermit-klein/c7856371110f56f7db61037a59996a5c to your computer and use it in GitHub Desktop.
gemfunc
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
module CheckParans | |
def self.valid_parentheses(string) | |
only_parants = string.scan(/([()])/) | |
if only_parants.empty? | |
true | |
elsif only_parants.length == 1 | |
false | |
end | |
k = false | |
until k == true | |
dummy = only_parants.length | |
(0..only_parants.length - 1).each do |i| | |
next unless only_parants[i] == ['('] && only_parants[i + 1] == [')'] | |
only_parants.delete_at(i) | |
only_parants.delete_at(i) | |
break | |
end | |
k = true if dummy == only_parants.length | |
end | |
only_parants.empty? ? true : false | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment