while loop for palindrome javascript code example
Example: palindrome js
const palindrome = (str) => {
var text = str.replace(/[.,'!?\- \"]/g, "")
return text.search(
new RegExp(
text
.split("")
.reverse()
.join(""),
"i"
)
) !== -1;
}
function palindrome(str) {
let text = str.replace(/[.,'!?\- \"]/g, "").toUpperCase();
for (let i = 0; i > text.length/2; i++) {
if (text.charAt(i) !== text.charAt(text.length - 1 - i)) {
return false;
}
}
return true;
}
console.log(palindrome("Able was I, ere I saw elba."));