Middle+
Live coding: write a function to check for a palindrome, ignoring spaces, punctuation, and case.
sobes.tech AI
Answer from AI
javascript function isPalindrome(str) { // Remove all spaces and punctuation, convert to lowercase const cleaned = str.toLowerCase().replace(/[^a-z0-9]/g, ''); // Check if the string is equal to its reverse return cleaned === cleaned.split('').reverse().join(''); }
// Example usage console.log(isPalindrome("A man, a plan, a canal, Panama")); // true console.log(isPalindrome("Hello, world!")); // false