Tell us what’s happening:
I already created two arrays to compare values. The first one removes all “special” characters, makes alphabetic characters into lower case and splits each characters into elements. My second array (revArray) takes the initial string makes alphabetic characters into lower case, splits each character and then reverse its position in the array.
I want to compare this two array with an if function (or any other function). I want to verify if the elements in the arrays are the same even when reversed (palindrome). I tried to create an simple if function using the === operator but that did not work out. I did see some stack overflow post saying I should use the .length method to compare the two arrays but I’m not sure how to apply that in my code or what is the reason behind it. Any help is appreciated, even if it is just link. Thank You
Your code so far
function palindrome(str) {
// Good luck!
var newArray = str.replace(/[\W_]/g, "").toLowerCase().split("");
var revArray = str.toLowerCase().split("").reverse("");
return newArray;
}
palindrome("bong");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393
.
Link to the challenge:
https://www.freecodecamp.org/challenges/check-for-palindromes