I made a palindrome checker that's supposed to be designed to be simple and easy to read. Please let me know what you think. I believe the time complexity is \$\mathcal{O}(n)\$ but I'm not too sure about that:
Challenge: You'll need to remove all non-alphanumeric characters (punctuation, spaces and symbols) and turn everything into the same case (lower or upper case) in order to check for palindromes.
function reverseString(str)
{
str = str.replace(/[^\w\s]|_/g, "").toLowerCase().split(" ").join("");
var array = [];
for(var i = str.length ; i >=0; i--)
{
array.push(str[i])
}
return(array.join(""));
}
reverseString("My age is 0, 0 si ega ym.");
function palindrome(str) {
str = str.replace(/[^\w\s]|_/g, "").toLowerCase().split(" ").join("");
if(str === reverseString(str))
{
return true;
}
else
{
return false;
}
}
reverseString("My age is 0, 0 si ega ym.");
should at least be something likeconsole.log(palindrome(reverseString("My age is 0, 0 si ega ym.")));
, and does your challenge ignore spaces? Because if they don't, your example string should return false while it doesn't. Please clarify the exact challenge. \$\endgroup\$