Hi - I know my code is really clunky (even compared to the “intermediate” solution ) but it’s working and that is a victory for me for now. However, it is failing ONE of the testcases, i.e. palindrome(“almostomla”) should return false
I cannot tell why. Can someone take a look at my code? Thank you in advance!
Your code so far
// remove non-alpha-numeric characters
str = str.replace(/[^0-9a-z]/gi, '');
str = str.replace(/\s/g, '');
//make everything lowercase
str = str.toLowerCase();
//build arrays of str - going forwards and backwards
var fwdarray=[];
fwdarray = str.split('');
var bkwdarray=[];
bkwdarray = str.split('');
bkwdarray.reverse();
//compare the 2 arrays to see if they are the same
for (i=0; i < fwdarray.length; i++){
// console.log(fwdarray);
// console.log(bkwdarray);
if (fwdarray[i]===bkwdarray[i]){
return true;
}else
return false;
}
}
palindrome("eye");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
.
Link to the challenge:
https://www.freecodecamp.org/challenges/check-for-palindromes