Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
Compairing two Arrays if they are equal is returning false even if they are the same

With the following code I'm checking if str is a palindrome. (A palindrome is a word or sentence that's spelled the same way both forward and backward). Even tho they are the same, the function is still giving me a false return... Why is that? I know I could join the arrays to single strings with .join('') but I still would like to know whats wrong with my code and why it's not working

function palindrome(str) {
    
      let newStr = str.toUpperCase().replace(/[^A-Z\d]/g, '').split('');
      let newStrRev = [...newStr].reverse();     //.reverse() is not destructive anymore
    
      console.log(typeof newStr, newStr);        //OUTPUT: object [ 'R', 'A', 'C', 'E', 'C', 'A', 'R' ]
      console.log(typeof newStrRev, newStrRev);  //OUTPUT: object [ 'R', 'A', 'C', 'E', 'C', 'A', 'R' ]
    
      if (newStr === newStrRev) {
        return true
      } else {
        return false
      }
    }
    
    console.log(palindrome("race car"));        //OUTPUT: false
about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda