Solution Review: Check Palindrome
This review provides a detailed analysis of the solution to check whether or not a string is a palindrome.
We'll cover the following...
Solution: Using Recursion
Press + to interact
function isPalindrome(testVariable) {// Base caseif (testVariable.length <= 1) { // Strings that have length 1 or 0 are palindromereturn true;}// Recursive caseelse if (testVariable[0] == testVariable[testVariable.length - 1]) { // compare the first and last elementsreturn isPalindrome(testVariable.substring(1, testVariable.length - 1));}return false;}// Driver Codeconsole.log(isPalindrome("madam"));
Explanation
...Access this course and 1400+ top-rated courses and projects.