Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/palindrome_ext/array.rb
Overview
Overrides Default Array Class by adding #palindrome? method.
Instance Method Summary collapse
-
#palindrome?(strict = true) ⇒ Boolean
Whether or not the array is a palindrome.
Instance Method Details
#palindrome?(strict = true) ⇒ Boolean
Returns Whether or not the array is a palindrome.
9 10 11 12 13 14 15 |
# File 'lib/palindrome_ext/array.rb', line 9 def palindrome?(strict = true) return self == reverse if strict arr = map { |x| x.to_s.downcase.tr("^a-z0-9", "") } arr.delete_if(&:empty?) arr == arr.reverse end |