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

153
Vistas
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
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