Skip to content

Instantly share code, notes, and snippets.

@gerardogc2378
Created March 13, 2017 23:26
Show Gist options
  • Save gerardogc2378/f7b5b6fd393c13861e9f4b939dda9d30 to your computer and use it in GitHub Desktop.
Save gerardogc2378/f7b5b6fd393c13861e9f4b939dda9d30 to your computer and use it in GitHub Desktop.
# 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