Created
December 28, 2011 06:24
-
-
Save stim371/1526706 to your computer and use it in GitHub Desktop.
Solutions to therubygame.com week 3 problems
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
# times are based on 25,000 iterations | |
# solution 1 / time: 1.47936483s | |
def capitalize(time) | |
string.split.each{|n| n.capitalize!}.join ' ' | |
end | |
# solution 2 / time: 2.32211853s | |
def capitalize(string) | |
string.downcase.gsub(/^\w|\s+\w/){|n| n.upcase} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment