js check the string is palindrome or not code example
Example 1: javascript palindrome check
const isPalindrome = str => str === str.split('').reverse().join('');
isPalindrome('abc');
isPalindrom('abcba');
Example 2: javascript palindrome check
function palindrome(str) {
var re = /[^A-Za-z0-9]/g;
str = str.toLowerCase().replace(re, '');
var len = str.length;
for (var i = 0; i < len/2; i++) {
if (str[i] !== str[len - 1 - i]) {
return false;
}
}
return true;
}
palindrome("A man, a plan, a canal. Panama");