Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
.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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!