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

152
Views
Every method on empty array looking for prime numbers

I have a pretty hard time understanding what is going on in this FreeCodeCamp exercise code:

function sumPrimes(num) {
  let primeNumbers = new Array;

  for (let i = 2; i <= num; i++) {
    if (primeNumbers.every(prime => i % prime !== 0)) {
      primeNumbers.push(i);
    }
  }
  return primeNumbers.reduce((sum, prime) => sum + prime);
}

console.log(sumPrimes(10));

Why does the every method here even work when the array (primeNumbers) is empty. And secondly how does the condition work with a parameter prime when there is nothing in the array from where does the function get the value for the parameter prime from?

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!