It works just fine with other palindromes (e.g "Able was I saw Elba.", "A man, a plan, a canal. Panama."), but fails with "almostoma".
function palindrome(str) {
str = str.toLowerCase();
str = str.split(" ").join("");
str = str.replace(",", "");
str = str.replace("_", "");
str = str.replace(".", "");
for (var i = 0; i < str.length; i++) {
if (str[i] == str[str.length - i - 1]) {
return true;
} else {
return false;
}
}
}
console.log(palindrome("almostoma"));