Skip to content

Instantly share code, notes, and snippets.

@elcortez
Created April 10, 2019 17:16
Show Gist options
  • Select an option

  • Save elcortez/b660c6be5c071df4d31beebe36f3b93d to your computer and use it in GitHub Desktop.

Select an option

Save elcortez/b660c6be5c071df4d31beebe36f3b93d to your computer and use it in GitHub Desktop.
def acronymise(string)
# look for first letter in each word
# concatenate in a string
# upcase
# return value
acronym = ""
string.split(" ").each do |word|
acronym += word[0].upcase
end
return acronym
end
p acronymise("Frequently Asked Question")
puts acronymise("Frequently Asked Question") == "FAQ"
p acronymise("Bois d'Arcy")
puts acronymise("Bois d'Arcy") == "BD"
p acronymise(" Hello World ")
puts acronymise(" Hello World ") == "HW"
p acronymise("")
puts acronymise("") == ""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment