I managed to get everything right except for the one that passes the string “1 eye for of 1 eye”.
the regex ignores the numbers for that specific string only, but it works on other strings like
“My age is 0, 0 si ega ym.” .
here is my code
function palindrome(str) {
// Good luck!
let strRegex = /\d*[a-z]||[a-z]*\d*/ig;
let newString = str.match(strRegex).toString().replace(/,/g,'').toLowerCase();
let reversed = str.match(strRegex).reverse();
let reversedString = reversed.toString().replace(/,/g, '').toLowerCase();
if(reversedString === newString){
return true;
}
else {
return false;
}
}
palindrome("1 eye for of 1 eye");