javascript paliandrome or not javascript code example

Example 1: 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");

Example 2: js palindrome number

isPalindrome = function(x) {
    if (x < 0) {
        return false;
    }
    
    return x === reversedInteger(x, 0);
};

reversedInteger = function(x, reversed) {
    if(x<=0) return reversed;
        reversed = (reversed * 10) + (x % 10);
        x = Math.floor(x / 10);
    
    return reversedInteger(x, reversed);
};