Created
April 10, 2019 17:16
-
-
Save elcortez/b660c6be5c071df4d31beebe36f3b93d 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 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