Need help with JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Hello everyone,
I’m doing this exercise with palindrome. I’ve removed all non-alphanumeric characters and make it lower case and then I iterate it backwards. when I use console.log(newStr) and console.log(newArr), to see the result. it shows both array containing the same thing if it’s plaindrome. but when i run if (newStr == newArr) apparently the result is not true.

below is the code that i wrote, please let me know where did it gone wrong.

Your code so far

function palindrome(str) {
  let newStr = str.replace(/([\W\_]+)(\w)/g,'$2').toLowerCase().split("");
  let newArr = [];
  for(let i = newStr.length-1; i>=0; i--){
    newArr.push(newStr[i]);
  }

  if(newArr == newStr) { 
    return true;
  }
  return false;
}

console.log(palindrome("2_A3*3#A2"));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

Comparing arrays like that won’t work in JavaScript.

console.log([1] == [1]) // false
1 Like

ah thats why, okay thanks!