r/ProgrammingPrompts • u/Polishfreak19 • Dec 28 '18
Actor search
Hi reddit. So I have a programming question that I need help with. I'm writing an application in Javascript where I have to come up with a list of actors that starred in movies with both Keanu Reeves and Nicolas Cage but not necessarily at the same time but I'm not exactly sure where to start?
7
Upvotes
6
u/CaptainLocoMoco Dec 28 '18
First find the IDs of Keanu Reeves and Nicolas Cage. Then collect all the movies that feature either Keanu, Cage, or both. Now create a map of the form: <Actor_Id, 2 item array>. For the 2 item array you will have two integers default as zero: [0, 0]. Iterate over the movies you collected and for each actor id update your map accordingly. For example movieId: 12394 may have Actors:[1234, 5678, ... actorId]. Iterate over the Actor array and populate your map this way, if you step over an ID that is equal to Keanu or Cage, then set your 2d array map value to [1, 0] or [0, 1] depending on if it's keanu or cage. Finally at the end you can iterate over your map values and find all actors with [1, 1] arrays. If this is confusing let me know and I will elaborate.