Hello, I am trying to solve the Palindrom algorithm and so far, when I check my code on my IDE it is working fine for all the conditions but fails in freecodecamp’s test on the followings :
- (“race car”) should return true
- (“A man, a plan, a canal. Panama”) should return true
- (“never odd or even”) should return true
- (“My age is 0, 0 si ega ym.”) should return true
- (“0_0 (: /-\ : ) 0-0”) should return true
all of the above conditions work appropriately with VS Code…
I would appreciate if someone could guide me here.Thanks
Your code so far
let cleanStr = "";
let list1 = [];
let list2 = [];
let result ="";
function palindrome(str) {
let finalStr = str.replace(/[^A-Z0-9]/ig, "");
finalStr = finalStr.toLowerCase();
for(let i in finalStr){
list1.push(finalStr[i]);
}
for(let i in finalStr){
list2.push(finalStr[i]);
}
list2 = list2.reverse();
let i = 0;
let _ = 0;
for( i in list1)
for( _ in list2)
if (list1[i]!=list2[i]){
result = "Not Palindrome"
}
if(result ==="Not Palindrome"){
return false;
} else{
return true;
}
}
palindrome("eye");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36
Challenge: JavaScript Algorithms and Data Structures Projects - Palindrome Checker
Link to the challenge: