How does reduce() work here?

Yes I completely understand the solution using every(), but I would really like to understand the other one. Where is the difference in the ()s?

let z = y.filter(arr => x
           .map(n => arr.includes(n) && arr[0] + arr[1] === 7))
           .reduce((a, b) => a && b);

Your ()s are not identical to the solution. I can only say that so many ways. Look at where every single pair opens and closes in the code I posted directly from the solutions page.

  // filter the collection
  return collection.filter(obj => souceKeys
      .map(key => obj.hasOwnProperty(key) && obj[key] === source[key])
      .reduce((a, b) => a && b)
   ); // <---- LOOK RIGHT HERE

1 Like

Start counting left and right parens :slight_smile: I’ll ask again, do you want to reduce the results of the map, or the results of the filter?

2 Likes

I finally got it, so it was all about the () placement.

1 Like