...

/

Solution Review: Check Palindrome

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 case
if (testVariable.length <= 1) { // Strings that have length 1 or 0 are palindrome
return true;
}
// Recursive case
else if (testVariable[0] == testVariable[testVariable.length - 1]) { // compare the first and last elements
return isPalindrome(testVariable.substring(1, testVariable.length - 1));
}
return false;
}
// Driver Code
console.log(isPalindrome("madam"));

Explanation

...
Access this course and 1400+ top-rated courses and projects.