Skip to content

Instantly share code, notes, and snippets.

@stim371
Created December 28, 2011 06:24
Show Gist options
  • Save stim371/1526706 to your computer and use it in GitHub Desktop.
Save stim371/1526706 to your computer and use it in GitHub Desktop.
Solutions to therubygame.com week 3 problems
# 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