If fn3
is substituted for fn2
in this example running in node 9.5.0 the console.log(totalUpvotes)
will log undefined
. IIUC the result should be the same (92)?
const posts = [{id: 1, upVotes: 2}, {id:2, upVotes: 89}, {id: 3, upVotes: 1}];
const fn2 = (totalUpvotes, currentPost) => totalUpvotes + currentPost.upVotes;
const fn3 = (totalUpvotes, currentPost) => {totalUpvotes + currentPost.upVotes}
const totalUpvotes = posts.reduce(fn2, 0);
console.log(totalUpvotes);