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

142
Visualizações
.every() prototype isn't working as expected

Obviously it works for people so I must just be dumb, but I am passing an array of boolean's through the .every() prototype and it ALWAYS appears to return true, even when it shouldnt. so heres the code

The function call is made

checkAnswer();

Then this function executes.

      const checkAnswer = () => {
    let arr = cardStyle.slice(lengthTest - 5, lengthTest);
    if (arr.every((x) => x === true)) {
      Alert.alert("Congratulations!", `You Won in ${rowCount} tries!`);
    }
  };

For a test case, this function uses the React State Variable "cardStyle", which equals [false,false,false,false,false] (Booleans, not strings) and "rowCount" which equals 1. Then there is a global variable lengthTest which is initially equal to 5.

The weird behavior is that no matter what, the condition (arr.every((x) => x === true)) always seems to evaluate to true, because the Alert box always pops up. What am I missing?

about 4 years ago · Juan Pablo Isaza
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