Last active
January 27, 2022 00:12
-
-
Save caioertai/dffe5e04177296b438a34125355ed2b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 acronymize(sentence) | |
# create empty arrays of letters | |
letters = [] | |
# separate the sentense into string | |
words = sentence.split | |
# iterate over words | |
words.each do |word| | |
# find the first letter of each word | |
# send the letter to uppercase | |
# add each letter to the array | |
letters.push(word[0].upcase) | |
end | |
# transform array into string (.join) | |
return letters.join | |
end | |
p acronymize("oh my god") | |
puts "", "Tests:" | |
puts acronymize("hello world").class == String | |
puts acronymize("oh my god") == "OMG" | |
puts acronymize("") == "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment