JavaScript Algorithms and Data Structures Projects - Palindrome Checker

newStr = [‘e’, ‘p’, ‘o’, ‘n’] instead of [‘n’, ‘o’, ‘p’, ‘e’]. why?
Your code so far

function palindrome(str) {
  const regEx = /\W/gi;
  let newStr = str.replace(regEx, '').toLowerCase().split('');
  let reversedArr = newStr.reverse()
  return newStr
  //return newStr === reversedArr;

}

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

Your browser information:

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

Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker

Link to the challenge:

.reverse() changes the array in place. It doesn’t make a new copy. So your newStr and reversedArr variables are both referencing the same array.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.