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

124
Views
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
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!