Last active
December 19, 2015 06:19
-
-
Save Papillard/5910865 to your computer and use it in GitHub Desktop.
nice little functions to get familiar with string & regexp..
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 palindrome? string | |
string.gsub(/\W/,"").downcase.reverse == string.gsub(/\W/,"").downcase | |
end | |
def count_words string | |
result = {} | |
string.downcase.split(/\W+/).each do |word| | |
result[word] = result[word] ? result[word] + 1 : 1 | |
end | |
result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment