I don't understand the test result

Tell us what’s happening:
I don’t understand why FreeCodeCamp says the result of this "1 eye for of 1 eye." should return False


function palindrome(str) {
//console.log(str)
let minuscula= str.toLowerCase()
//console.log(minuscula)
const flag=/[a-z]/g

let arr1= minuscula.match(flag) 

let word1="";
let word2="";

if(arr1== null){
  return true
} else{

  for(let i=0; i<arr1.length; i++){
    word1 += arr1[i]
  }

  console.log(word1)
  for(let i= arr1.length-1; i>=0; i--){
    word2 +=arr1[i]
  }
  console.log(word2)

  if(word1 === word2){
    return true
  }else{
    return false
  }

}

}


console.log(palindrome("1 eye for of 1 eye."))


Challenge: Palindrome Checker

Link to the challenge:

because" 1 eye for of 1 eye." is not a palindrome. With the punctuation and space removed, the string becomes: “1eyeforof1eye”, you can see the first 4 characters “1eye” should mean the end 4 characters are “eye1”, but it is not.

Thanks!! I find the error , the code was only looking for alphabetic character and not alphanumeric characters, without the numbers the sentence was palindrome “eyeforofeye”.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.