-
-
Save anonymous/3dd8b30dad6a6faedfa8 to your computer and use it in GitHub Desktop.
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 titleize(s) | |
words = s.split.map do |word| | |
if %w(the and over).include?(word) | |
word | |
else | |
word.capitalize | |
end | |
end | |
words.first.capitalize! | |
words.join(" ") | |
end | |
title ("jaws") ===> Jaws | |
title ("david copperfield") ===> David Copperfield | |
title ("war and peace") ===> War and Peace | |
title ("bride over the river kwai") ===> Bridge over the River Kwai |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment