function palindrome(str) { // Good luck! var a = str.replace(/\s|[0-9_]|\W|[#$%^&*()]/g, "").toLowerCase(); if (a === a.split("").reverse().join("")) { return true; } return false; } palindrome("eye"); palindrome("1 eye for of 1 eye.") //should return false. I have done this task on freecodecampus.com. Can anyone tell me why it should give false? If we are removing dot and punctuations, then isn't it right that it should return true?
/[^a-zA-Z0-9]+/ginstead, which literally matches non-alphanumeric characters?