Created
June 27, 2018 10:37
-
-
Save rodloboz/7af6d4f178ecffe97ae03c60169b8e03 to your computer and use it in GitHub Desktop.
Acronymize
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(string) | |
# TODO: write a method that returns | |
# the acronym for the given string | |
# 1. Split the string into words | |
# 2. Take the first letter of each word | |
# & capitalize them | |
# 3. Join the first letters together | |
# 4. Return the result | |
words = string.split(" ") | |
# p words - debugging | |
acronym = "" | |
words.each do |word| | |
acronym += word[0].upcase | |
end | |
# ["freq", "asked", "questions"] - initial arr | |
# [ "F", "A", "Q"] -> transformed arr | |
words.map do |word| | |
word[0].upcase | |
end.join | |
# acronym | |
end | |
# TDD - Tests | |
puts acronymize("Central Intelligence Agency") == "CIA" | |
puts acronymize("central intelligence agency") == "CIA" | |
puts acronymize("Central Intelligence Agency".upcase) == "CIA" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment