Examples
Write isPalindrome so that the following cases hold.
- Input
isPalindrome("Racecar")Outputtrue - Input
isPalindrome("A man, a plan, a canal: Panama")Outputtrue - Input
isPalindrome("hello")Outputfalse
1 more hidden test cases - 4 in total will be graded.
Answer
text
function isPalindrome(str) {
const clean = str.toLowerCase().replace(/[^a-z0-9]/g, "");
return clean === clean.split("").reverse().join("");
}
isPalindrome("Racecar"); // true
