Created
July 3, 2012 06:37
-
-
Save npras/3038097 to your computer and use it in GitHub Desktop.
Ruby Challenge 3: Capitalizing words within a string
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
# Challenge 3: http://www.therubygame.com/challenges/3/submissions | |
str = "The small brown & ginger fox JUMPED OVER the gate" | |
# output = "The Small Brown & Ginger Fox Jumped Over The Gate" | |
# Algorithm: | |
# 1. downcase #{str} | |
# 2. to_a | |
# 3. capitalize on each array elements | |
# 4. merge as str | |
def Capitalize(str) | |
str.split.each {|x| x.capitalize!}.join ' ' | |
end | |
puts "ip: #{str}" | |
puts "op: #{Capitalize str}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment