Palindrome in Javascript

How to check string from both side left to right and right to left.

something like prarp this should be give us true.

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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *