Skip to content

Instantly share code, notes, and snippets.

@caioertai
Last active January 27, 2022 00:12
Show Gist options
  • Save caioertai/dffe5e04177296b438a34125355ed2b0 to your computer and use it in GitHub Desktop.
Save caioertai/dffe5e04177296b438a34125355ed2b0 to your computer and use it in GitHub Desktop.
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