Commit 8f39871a authored by Robert Chatley's avatar Robert Chatley
Browse files

doubling and reverse encoders - full duplication

parents
class ReverseEncoder
def encode(str)
words = str.split(" ")
result = []
for word in words
result << encode_word(word)
end
result.join(" ")
end
def encode_word(word)
word.reverse
end
end
class DoublingEncoder
def encode(str)
words = str.split(" ")
result = []
for word in words
result << encode_word(word)
end
result.join(" ")
end
def encode_word(word)
word * 2
end
end
\ No newline at end of file
require './encoder'
describe ReverseEncoder do
encoder = ReverseEncoder.new
it "can reverse a single word" do
expect(encoder.encode("abcd")).to eq("dcba")
end
it "can reverse each word in a sentence" do
expect(encoder.encode("abcd 123")).to eq("dcba 321")
end
end
describe DoublingEncoder do
encoder = DoublingEncoder.new
it "can double a single word" do
expect(encoder.encode("abcd")).to eq("abcdabcd")
end
it "can double each word in a sentence" do
expect(encoder.encode("abcd 123")).to eq("abcdabcd 123123")
end
end
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment