title: Javascript Program for find common elements in two array
body: <p>Recently I had an interview question as follows:
  Let us consider we have two sorted arrays of different length. Need to find the common elements in two arrays. </p>
  
  <pre><code>var a=[1,2,3,4,5,6,7,8,9,10];
  var b = [2,4,5,7,11,15];
  for(var i=0;i&lt;a.length;i++){
      for(var j=0;j&lt;b.length;j++){
          if(a[i]==b[j]){
              console.log(a[i],b[j])
          }
      }
  }
  </code></pre>
  
  <p>I wrote like above. The interviewer said let now assume a have 2000 elements and b have 3000 elements. Then how you wrote in a more efficient way?</p>
  
  <p>Please explain your answers with sample code. So I can understand more clearly.</p>