Question: So , the input Able was I ere I saw Elba should count as a palindrome. Approach: Let's assume the signature of our function is
So the input "Able was I ere I saw Elba" should count as a palindrome.
Approach:
Let's assume the signature of our function is palindrome s where is the input string. In the body of your function, check if the length of is less than If so just return true because a string containing one letter is the same backwards and forwards. If length of is greater than take the first and last letters off of the string and determine if they are equal. If not, return false. But if they are equal, recursively call palindrome on the substring of that excludes both the first and last character. That means the length of the new string should be two characters less than that of the original string.
Writing any explicit loop in your code results a for this question. Remember to provide pre and postconditions.
Now copypaste the following trace table in your word file and trace your function palindrome for when is initially "racecar". As a guideline, we have populated the tables with the values for the first call and the corresponding returned values for each of those calls. As ever, the first table is populated top down ie time elapses from row torow whereas the returned value table is populated bottomup ie time elapses from row to row You may want to use debugging features console. log to observe thesevalues as your program runs.
tablecall#svalue returned to thiscall
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
