Skip to content

Instantly share code, notes, and snippets.

@mosdevly
Last active August 29, 2015 14:09
Show Gist options
  • Save mosdevly/ed4252d8e2121a902df6 to your computer and use it in GitHub Desktop.
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.
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