Coding Test: Find out if the Given string is Palindrome.

Challenge: Find out if the given string is palindrome or not.

Example:

Input: A man, a plan, a canal. Panama

Output: True



function palindrome(str) {

var re = /[\W_]/g;

var lowRegStr = str.toLowerCase().replace(re, '');

var reverseStr = lowRegStr.split('').reverse().join('');

return reverseStr === lowRegStr;

}


Try it yourself:

 

Another Solution:


function palindrome(str) {

var re= /[^A-Za-z0-9]/g;

str=str.toLowerCase().replace(re, '');

var len=str.length;

for (vari=0; i<len/2; i++) {

if (str[i] !==str[len-1-i]) {

returnfalse;

}

}

returntrue;

}
console.log(palindrome("A man, a plan, a canal. Panama"));