Instructions
Create a function palindrome? that returns true if a string
reads the same forwards and backwards.
Ignore case when comparing.
Example: palindrome?("Racecar") returns true
Hints:
- Use .downcase to normalize case
- Compare string with its reverse
- str.downcase == str.downcase.reverse
Your Code
def palindrome?(str) str.downcase == str.downcase.reverse end
RSpec.describe "palindrome?" do
it "returns true for racecar" do
expect(palindrome?("racecar")).to be true
end
it "is case insensitive" do
expect(palindrome?("Racecar")).to be true
end
it "returns false for hello" do
expect(palindrome?("hello")).to be false
end
it "returns true for single char" do
expect(palindrome?("a")).to be true
end
end
Results
Click "Run Tests" to see results