M121 - ch1 - Understanding $setIntersection


I’m trying to understand the answer for the last quiz on Chapter 1. I used stack overflow to try and come up with a radically different solution(still trying to figure it out). But my question is with the answer given, specifically with $setIntersection:

It seems to me, that using this would eliminate the duplicates, instead of return them so that we could count them. What am I missing here?

Thank you

Hey @Nicholas_90117 you’re quite right about $setIntersection removing/ignoring duplicates.

In this scenario, $setIntersection is used to find actors who appear as casts, directors and writers in any given movie. Once we can prove this (using $setIntersection), we can go ahead and count how many movies this occurs. We’re not counting the people, we’re counting the movies. So it doesn’t matter if we eliminate or keep the duplicate casts/directors/writers entries because it will have no bearing on the movie count.

Makes sense?

1 Like

That does make sense, thanks for clarifying @007_jb

You’re welcome! :beers: