Extract split method from loop

This commit is contained in:
Jessica Kwok 2021-07-02 12:45:20 -07:00
parent 2375a7f97f
commit b40fe95c43

View file

@ -25,10 +25,11 @@
def almost_palindrome_checker(string)
p1 = 0
p2 = string.length - 1
array = string.split('')
while p1 < p2
if string.split('')[p1] != string.split('')[p2]
return palindrome_checker(string, p1, p2 - 1) || palindrome_checker(string, p1 + 1, p2)
if array[p1] != array[p2]
return palindrome_checker(array, p1, p2 - 1) || palindrome_checker(array, p1 + 1, p2)
end
p1 += 1
p2 -= 1
@ -37,9 +38,9 @@ def almost_palindrome_checker(string)
true
end
def palindrome_checker(string, p1, p2)
def palindrome_checker(array, p1, p2)
while p1 < p2
if string.split('')[p1] != string.split('')[p2]
if array[p1] != array[p2]
return false
end
p1 += 1