Check for palindromes - need help

Check for palindromes - need help
0.0 0


Hi. can anybody please tell me whats wrong in this Check for Palindromes code? I think i am doing everything correct but i am getting false for following code :

function palindrome(str) {
// Good luck!
var newStr = str.replace(/[^a-z0-9]/gi,"");
var array = newStr.split("");
var array2 = array.slice();

if(array == array2
) {
return true;

else { return false;}

palindrome (“race car”);



  • Which test is failing?
  • what is different about that string?
  • what exactly is your regex matching?


you are comparing arrays. you should try to compare strings.


I was able to get a true result by creating a string from each array with join and comparing the strings.


(array == array2) will always be false because array and array2 are different arrays.

The == operator doesn’t compare the values inside the arrays.

It’s easier to compare strings but you can also make your code work by comparing array elements with a loop.