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

126
Vistas
Why is the 0 needed after "(arr[i] || 0)"?

For the code below I wonder why the the last "0" after "(arr[i] || 0)" is needed?

I aknowledge that without this "0" the code doesnt run as intended, but I do not actually get what that last "0" after "," makes it work.

Could someone explain it?

function addTogether (...arrays) {
    let result = [];
    let arrayLength = Math.max(...arrays.map(array => array.length));
    for (let i = 0; i < arrayLength; i++) {
      result.push(arrays.reduce((sum, arr) => sum + (arr[i] || 0), 0));
    }
    return result
  }
  
  test(addTogether([1, 2, 3], [4, 5], [6]), [11, 7, 3]);

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