Monday, August 19, 2013

Coderbyte: Letter Capitalize (Ruby)

PROBLEM

Have the function LetterCapitalize(str) take the str parameter being passed and capitalize the first letter of each word. Words will be separated by only one space.

SOLUTION

def LetterCapitalize(string)
    new_string = ""
    string.split.each do |word| 
        new_string = new_string + "#{word.capitalize} "
    end
    return new_string  
end

print LetterCapitalize(STDIN.gets)