palindrome rearranging javascript code example
Example 1: palindrome in javascript
function palindrome(str) {
var len = str.length;
var mid = Math.floor(len/2);
for ( var i = 0; i < mid; i++ ) {
if (str[i] !== str[len - 1 - i]) {
return false;
}
}
return true;
}
Example 2: Function Palindrome JavaScript
function isPalindrome(str) {
str = str.replace(/\W/g, '').toLowerCase();
return (str == str.split('').reverse().join(''));
}
console.log(isPalindrome("level"));
console.log(isPalindrome("levels"));
console.log(isPalindrome("A car, a man, a maraca"));