Skip to content

Instantly share code, notes, and snippets.

@rodloboz
Created January 16, 2019 17:43
Show Gist options
  • Save rodloboz/f0b9f4a4648ef66aca29d6eca0b206af to your computer and use it in GitHub Desktop.
Save rodloboz/f0b9f4a4648ef66aca29d6eca0b206af to your computer and use it in GitHub Desktop.
Ruby 04-Flow-Control Livecode
# What is an acronym:
# WTF => what the f*ck
# CIA => central intelligence agency
# FBI => federal bureau of investigation
# Pseudocode:
# 1) we start with a String
# 2) split the sentence into words => Array
# delete ["of", "the", "a"]
# 3) get the first letter of each word #each/map
# 4) upcase the first letter of each word #upcase
# 5) add upcased initials together #join
FILTERS = ["of", "the", "a"]
def acronymize(sentence)
# TODO: Build an acronym from the sentence
words = sentence.split
FILTERS.each do |filter|
words.delete(filter)
end
# letters = []
# words.each do |word|
# letters << word[0].upcase
# end
letters = words.map do |word|
word[0].upcase
end
#. do end
# words.map { |word| word[0].upcase }.join
letters.join
end
subject = "central intelligence agency"
expected = "CIA"
puts acronymize(subject) == expected
subject = "federal bureau of investigation"
expected = "FBI"
puts acronymize(subject) == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment