Instructions
Create a function reverse_string that takes a string and returns it reversed.
Example: reverse_string("hello") returns "olleh"
Hints:
- Ruby strings have a .reverse method
- You can also use .chars.reverse.join
- The simplest solution is often the best
Your Code
def reverse_string(str) str.reverse end
RSpec.describe "reverse_string" do
it "reverses hello" do
expect(reverse_string("hello")).to eq("olleh")
end
it "reverses ruby" do
expect(reverse_string("ruby")).to eq("ybur")
end
it "handles empty string" do
expect(reverse_string("")).to eq("")
end
it "handles single character" do
expect(reverse_string("a")).to eq("a")
end
end
Results
Click "Run Tests" to see results
1 / 6
Next: Palindrome Check