Sequence NODE_142
EasyCheck if String is Palindrome
JavaScript
Technical Specification
Check whether a given string reads the same forwards and backwards. Ignore case and non-alphanumeric characters.
Input/Output Samples
Input:"madam"
Output:true
Input:"A man, a plan, a canal: Panama"
Output:true
Input:"hello"
Output:false
Optimal Logic Path
function isPalindrome(str) {
const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, "");
const reversed = cleaned.split("").reverse().join("");
return cleaned === reversed;
}Architectural Deep-Dive
By cleaning the string we ignore spaces and punctuation. Then we reverse and compare to check if it’s a palindrome.