title: Finding intersection of two arrays in Node.js
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript">Simplest code for array intersection in JavaScript</a></p>
  </blockquote>
  
  <p>I am writing an app with Mongodb and Nodejs. I have a 'students' collection which contains, among other things, an array with a list of all the courses (course IDs, which refer to documents in the 'courses' collection) a particular student has taken.</p>
  <p>I have 2 students, StudentA and StudentB. I want to see if these two students took any common courses.</p>
  <p>I have already retrieved the studentA and studentB documents from Mongodb. I want to find the intersection between these 2 arrays in Node.js app.</p>
  <p>One approach I thought of was to go through the first array, create a hash map with the objectid as the key. Then go through the 2nd array and try to increment the value by 1. In the end, all the entries with a value of 1 are the intersecting elements.</p>
  <p>Is there a better approach?</p>