Created
March 13, 2017 23:26
-
-
Save gerardogc2378/f7b5b6fd393c13861e9f4b939dda9d30 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Variable Switch | |
a, b = b, a | |
# Palindrome | |
def palindrome(value = "") | |
value.downcase == value.downcase.reverse | |
end | |
# Balanced Brackets | |
def b_brackets(value = "") | |
return false if value.size % 2 != 0 | |
h = {"(" => ")", "{" => "}", "[" => "]"} | |
l_part = value[0..value.size / 2 - 1] | |
r_part = value.reverse[0..value.size / 2 - 1] | |
tmp = "" | |
l_part.split("").each { |item| tmp += h[item] } | |
return tmp == r_part | |
rescue | |
return false | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment