Skip to content

Instantly share code, notes, and snippets.

@anchietajunior
Created November 20, 2023 10:46
Show Gist options
  • Save anchietajunior/c5b0f6d31b15841100cd0672b5faeeee to your computer and use it in GitHub Desktop.
Save anchietajunior/c5b0f6d31b15841100cd0672b5faeeee to your computer and use it in GitHub Desktop.
Palindrome algorithm
def palindrome?(word)
left = 0
right = word.length - 1
while left < right
return false if word[left] != word[right]
left += 1
right -= 1
end
true
end
# Tests
require 'rspec/autorun'
describe 'palindrome?' do
it 'returns true for a palindrome word' do
expect(palindrome?("HANNAH")).to be true
end
it 'returns false for a non-palindrome word' do
expect(palindrome?("GAGA")).to be false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment