-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Karis - Edges - Palindrom Check #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,43 @@ | ||
# A method to check if the input string is a palindrome. | ||
# Return true if the string is a palindrome. Return false otherwise. | ||
def palindrome_check(my_phrase) | ||
raise NotImplementedError | ||
return false if !my_phrase | ||
return true if my_phrase == "" | ||
return true if my_phrase.length == 1 | ||
|
||
min = 0 | ||
max = my_phrase.length - 1 | ||
check = false | ||
|
||
# first check if string is empty or not | ||
# if not empty then compare the pair | ||
# if at least one of them is empty then move onto next index until it is not empty | ||
# then compare | ||
# if match continue moving up the index until min > max | ||
# if at least one pair that does not match then return false for good | ||
|
||
|
||
until min > max | ||
# unless my_phrase[min] == " " || my_phrase[max] == " " | ||
until my_phrase[min] != " " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the two nested inner loops, continue to check and confirm that min is less than max before comparing the character at the index min (or max) with a white space. |
||
min += 1 | ||
end | ||
|
||
until my_phrase[max] != " " | ||
max -= 1 | ||
end | ||
|
||
if my_phrase[min] == my_phrase[max] | ||
check = true | ||
else | ||
return false | ||
end | ||
# end | ||
|
||
min += 1 | ||
max -= 1 | ||
# require 'pry'; binding.pry | ||
end | ||
|
||
return check | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the code reaches this point, you'll always be returning true. So you could get rid of the variable |
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could combine lines 5 and 6 to be:
return true if my_phrase.length < 2