Created
April 18, 2019 18:41
-
-
Save fractalatcarf/0c5a4f27fef6757c759c59061a4fa40e to your computer and use it in GitHub Desktop.
live code de ce soir
This file contains 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 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" | |
This file contains 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 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 | |
This file contains 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 "../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 |
This file contains 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 "../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