Last active
August 29, 2015 14:09
-
-
Save mosdevly/ed4252d8e2121a902df6 to your computer and use it in GitHub Desktop.
Capitalize - Write a method which will capitalize the first letter of each word in a string. Do not use the #capitalize method.
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 cap(str) | |
words = str.split(" ") | |
idx = 0 | |
while idx < words.length | |
word = words[idx] | |
word[0] = word[0].upcase # change the word within array | |
idx += 1 | |
end | |
p words.join(" ") | |
end | |
cap("we love bananas") | |
cap("this beer is delicious") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment