Skip to content

Instantly share code, notes, and snippets.

@rodloboz
Created July 29, 2020 15:45
Show Gist options
  • Save rodloboz/4b02a185c2d984ecd60fc8ae5f939958 to your computer and use it in GitHub Desktop.
Save rodloboz/4b02a185c2d984ecd60fc8ae5f939958 to your computer and use it in GitHub Desktop.
Acronymize solution
# CEO - Chief Executive Officer
# ASAP - as soon as possible
# DIY - DO IT YOURSELF
def acronymize(sentence)
# sentence.upcase.split.map(&:chr).join
# TODO: return the acronym for the sentence
# split the sentences into words
# take the first letter of each word
# capitalize it
# join it together
# return a string
words = sentence.split
# letters = []
letters = ""
words.each do |word|
# letters << word[0].capitalize
letters += word[0].capitalize
end
# letters.join
letters
end
require_relative './acronymize'
RSpec.describe "#acronymize" do
it "returns the acronym for sentences with capital words" do
sentence = "Chief Executive Officer"
output = acronymize(sentence)
expect(output).to eq("CEO")
end
it "returns the acronym for downcased sentences" do
sentence = "as soon as possible"
output = acronymize(sentence)
expect(output).to eq("ASAP")
end
it "return the acronym for upcased sentences" do
sentence = "DO IT YOURSELF"
output = acronymize(sentence)
expect(output).to eq("DIY")
end
end
# CEO - Chief Executive Officer
# ASAP - as soon as possible
# DIY - DO IT YOURSELF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment