From aa0d724180ec819821bec2cbe72e3abecb72f191 Mon Sep 17 00:00:00 2001 From: Naheed Arang Date: Tue, 16 Oct 2018 21:41:18 -0700 Subject: [PATCH] tests pass --- lib/palindrome_check.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/palindrome_check.rb b/lib/palindrome_check.rb index d60efd0..174b4c9 100644 --- a/lib/palindrome_check.rb +++ b/lib/palindrome_check.rb @@ -1,5 +1,24 @@ # A method to check if the input string is a palindrome. # Return true if the string is a palindrome. Return false otherwise. +require 'pry' def palindrome_check(my_phrase) - raise NotImplementedError + if my_phrase == nil + return false + end + i = 0 + j = my_phrase.length - 1 + while i < j do + until my_phrase[i] != " " + i +=1 + end + until my_phrase[j] != " " + j -= 1 + end + if my_phrase[i] != my_phrase[j] + return false + end + i += 1 + j -= 1 + end + return true end