%%js
// Function to check if a string is a palindrome
function palindrome(inputStr) {
// Remove non-alphanumeric characters (including spaces, punctuation) and convert to lowercase
const cleanStr = inputStr.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
// Check if the cleaned string is equal to its reverse
return cleanStr === cleanStr.split('').reverse().join('');
}
// Test cases
console.log(palindrome("did you know that sahas spelled backwards is sahas")); // Output: false
console.log(palindrome("hi")); // Output: false
console.log(palindrome("madam")); // Output: true
console.log(palindrome("A man, a plan, a canal, Panama")); // Output: true
console.log(palindrome("Was it a car or a cat I saw?")); // Output: true
console.log(palindrome("")); // Output: true (empty string is trivially a palindrome)
console.log(palindrome("No 'x' in Nixon")); // Output: true