I tried to solve this exercice with 2 diferent ways and I still can’t pass all the tests. Can someone tell me what i’m doing wrong?
Here’s my first attempt:
function Palindrome(str) {
let array = str.toLowerCase().split(/\W_/g);
for(let i = 0; i <array.length; i++) {
for(let j= array.length-1; j>=0; j--) {
if(i!==j) {
return false;
}
return true;
}
}
}
And here’s my second attempt;
function palindrome(str) {
let char = /[\W_]/g;
let lowerC = str.toLowerCase().replace(char, '');
let rev = lowerC.split('').reverse().join('');
return rev === lowerC;
}