Please explain reduce method


    const totalYears = inventors.reduce((total , inventor) => {
      return total+ (inventor.passed -inventor.year)
    }, 0);

okay so I have been watching a tutorial on this and i get the basic of it. It’s just another way to loop through information to get answers. How does the function know to get all the values then do the final total calculation.

I would imagine every time it went through the array it would return an answer like 80, 70, 60, 60, 90. Then how would this then all be added together? what part of the function implies that?

Just to be clear it is my first time using the reduce method .

A good explanation:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.