I have been trying this question for a while, I am not sure what is wrong with my code.
Odd number array with return true could not passed…
Shall I just go for split. reverse. join function then compare the two strings, instead of comparing arrays…
function palindrome(str) {
// Good luck!
str = str.replace(/[^a-zA-Z 0-9]+/g,'');
str = str.toLowerCase();
var arrNum = str.length;
// make it int not flort
var middlePoint = Math.floor (arrNum /2);
var j = 0;
while( j < middlePoint)
{
if (str [j] == str [arrNum -1 - j])
{
j++;
//if array is odd number
if (j == (arrNum -1-j))
{
return true;
}
}
else
{
return false;
}
}
return true;
}