Created
July 29, 2020 15:45
-
-
Save rodloboz/4b02a185c2d984ecd60fc8ae5f939958 to your computer and use it in GitHub Desktop.
Acronymize solution
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
# 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 | |
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
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