d. Problem 4. Devise a function that receives a string and determines if it is a palindrome. Make the function evaluate palindromes in a case insensitive way. 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 s is the input string. In the body of your function, check if the length of s is less than 2. If so, just return true because a string containing one letter is the same backwards and forwards. If length of s is greater than 2, 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 sub-string of s 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 0 for this question. Remember to provide pre- and post-conditions. Now copy/paste the following trace table in your Word file and trace your function palindrome (s) for when s 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 (i.e. time elapses from row x torow x+1) whereas the returned value table is populated bottom-up (i.e. time elapses from row x to row x-1). You may want to use debugging features console.log to observe these values as your program runs. call# 1 "racecar" 2 "aceca" value returned to this call TRUE TRUE
d. Problem 4. Devise a function that receives a string and determines if it is a palindrome. Make the function evaluate palindromes in a case insensitive way. 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 s is the input string. In the body of your function, check if the length of s is less than 2. If so, just return true because a string containing one letter is the same backwards and forwards. If length of s is greater than 2, 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 sub-string of s 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 0 for this question. Remember to provide pre- and post-conditions. Now copy/paste the following trace table in your Word file and trace your function palindrome (s) for when s 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 (i.e. time elapses from row x torow x+1) whereas the returned value table is populated bottom-up (i.e. time elapses from row x to row x-1). You may want to use debugging features console.log to observe these values as your program runs. call# 1 "racecar" 2 "aceca" value returned to this call TRUE TRUE
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Please help me with these questions using JavaScript
![d. Problem 4. Devise a function that receives a string and determines if it is a
palindrome. Make the function evaluate palindromes in a case insensitive way.
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 s is the input
string. In the body of your function, check if the length of s is less than 2. If so, just
return true because a string containing one letter is the same backwards and
forwards. If length of s is greater than 2, 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 sub-string of s 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 0 for this question. Remember to provide
pre- and post-conditions.
Now copy/paste the following trace table in your Word file and trace your function
palindrome (s) for when s 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 (i.e. time elapses
from row x torow x+1) whereas the returned value table is populated bottom-up
(i.e. time elapses from row x to row x-1). You may want to use debugging features
console.log to observe these values as your program runs.
call#
1
"racecar"
2
"aceca"
value returned to this
call
TRUE
TRUE](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1dd8a929-5d8c-435d-8504-b14d573d34d5%2F201d8d67-cc5d-483a-819c-5b3004074c0e%2Fj4qwlto_processed.jpeg&w=3840&q=75)
Transcribed Image Text:d. Problem 4. Devise a function that receives a string and determines if it is a
palindrome. Make the function evaluate palindromes in a case insensitive way.
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 s is the input
string. In the body of your function, check if the length of s is less than 2. If so, just
return true because a string containing one letter is the same backwards and
forwards. If length of s is greater than 2, 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 sub-string of s 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 0 for this question. Remember to provide
pre- and post-conditions.
Now copy/paste the following trace table in your Word file and trace your function
palindrome (s) for when s 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 (i.e. time elapses
from row x torow x+1) whereas the returned value table is populated bottom-up
(i.e. time elapses from row x to row x-1). You may want to use debugging features
console.log to observe these values as your program runs.
call#
1
"racecar"
2
"aceca"
value returned to this
call
TRUE
TRUE
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education