Skip to content

Instantly share code, notes, and snippets.

@fractalatcarf
Created April 18, 2019 18:41
Show Gist options
  • Save fractalatcarf/0c5a4f27fef6757c759c59061a4fa40e to your computer and use it in GitHub Desktop.
Save fractalatcarf/0c5a4f27fef6757c759c59061a4fa40e to your computer and use it in GitHub Desktop.
live code de ce soir
def acronymizer(string)
words = string.split(" ")
words.map{ |word| word[0].upcase}.join
end
# p acronymizer("What the fuck") #=> "WTF"
# p acronymizer("save our soul") #=> "SOS"
# p acronymizer("read the f**** manual") #=> "RTFM"
def encrypt(string)
alphabet = ("A".."Z").to_a
letters = string.split("")
new_letters = letters.map do |letter|
letter_index = alphabet.index(letter)
alphabet[letter_index-3]
end
return new_letters.join
end
require_relative "../acronymizer"
describe "#acronymize" do
it "returns an empty string when passed an empty string" do
actual = acronymizer("")
expected = ""
expect(actual).to eq(expected) # passes if `actual == expected`
end
it "returns WTF" do
actual = acronymizer("What the fuck")
expected = "WTF"
expect(actual).to eq(expected) # passes if `actual == expected`
end
it "returns SOS" do
actual = acronymizer("save our soul")
expected = "SOS"
expect(actual).to eq(expected) # passes if `actual == expected`
end
it "returns RTFM" do
actual = acronymizer("read the f**** manual")
expected = "RTFM"
expect(actual).to eq(expected) # passes if `actual == expected`
end
end
require_relative "../encrypt"
describe "#encrypt" do
it "simple encryption should work" do
actual = encrypt("DEF")
expected = "ABC"
expect(actual).to eq(expected) # passes if `actual == expected`
end
it "encryption of A should work" do
actual = encrypt("A")
expected = "X"
expect(actual).to eq(expected) # passes if `actual == expected`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment