title: Finding the intersection of two arrays in Javascript
body: <p>This was an Amazon interview question I had an my answer was </p>
  
  <pre><code>function intersection ( A , B ) 
  {
      var C = [];
      for ( var a in A ) if ( B.indexOf(a) != -1 ) C.push(a);
      return C;
  }
  </code></pre>
  
  <p>and he asked what the order of complexity was and I said, and I quote exactly,</p>
  
  <blockquote>
    <p>O(m * n) where m=A.length and n=B.length</p>
  </blockquote>
  
  <p>and he was saying there's a better way to do it and I was like WTF??????? He was saying use <code>A</code> and <code>B</code> as Objects and I was like </p>
  
  <blockquote>
    <p>"But you said these were <strong>arrays</strong> That was your question!!!!"</p>
  </blockquote>
  
  <p>Can someone help me out here?</p>