palindrome js solution code example
Example 1: javascript palindrome check
const isPalindrome = str => str === str.split('').reverse().join('');
// Examples
isPalindrome('abc'); // false
isPalindrom('abcba'); // true
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);
};