0

Obviously, a hash would not work for this kind of test. Anyways, here's what I have so far:

module Enumerable
  def palindrome?
    arr = []
    self.reverse_each do |x|
      arr << x
    end
    self == arr
  end
end

Another idea I had was to cycle through arr and self element by element with a for loop to check.

Rishi
  • 945
  • 2
  • 15
  • 23

2 Answers2

2
x = 'Tiger'
p "#{x} is planidrome" if x ==  x.reverse #=> no ouput
x = 'RADAR'
p "#{x} is planidrome" if x ==  x.reverse #=> "RADAR is planidrome"

module Enumerable
  def palindrome?
    p  self.to_a ==  self.to_a.reverse
  end
end
['r','a','d','a','r'].palindrome? #=> true
Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
2
module Enumerable
  def palindrome?
    a = to_a
    a == a.reverse
  end
end
dbenhur
  • 20,008
  • 4
  • 48
  • 45