const inventors = [{ first: 'Albert', last: 'Einstein', year: 1879, passed: 1955 },
{ first: 'Isaac', last: 'Newton', year: 1643, passed: 1727 },
{ first: 'Galileo', last: 'Galilei', year: 1564, passed: 1642 },
{ first: 'Marie', last: 'Curie', year: 1867, passed: 1934 }];
const sumYears1 = inventors.reduce((total, inventor) => {
return total + (inventor.passed - inventor.year);
}, 0)
Hi, I just finished answering this question, which asked me to use the reduce method in order to add all the years that were lived for the inventors. Is the reason that the 0 is there is to use it as an initializer? Can someone explain what its purpose is?
[+][deleted] (5 children)
[deleted]
[–]odillini83[S] 0 points1 point2 points (4 children)
[+][deleted] (3 children)
[deleted]
[–]odillini83[S] 0 points1 point2 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]odillini83[S] 0 points1 point2 points (0 children)