Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
.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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda