mirror of
https://github.com/TheAlgorithms/Ruby
synced 2024-12-26 21:58:56 +01:00
Extract split method from loop
This commit is contained in:
parent
2375a7f97f
commit
b40fe95c43
1 changed files with 5 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue