title: Comparing and Filtering two arrays
body: <p>I've been trying to implement a function where given with two arrays,</p>
  
  <p><strong>array1</strong>'s elements is used as conditions to filter out elements in <strong>array2</strong>.</p>
  
  <p>For instance:</p>
  
  <pre><code>array1= [apple, grapes, oranges]
  
  array2= [potato, pears, grapes, berries, apples, oranges]
  </code></pre>
  
  <p>After feeding into a function, array2 should have elements as such:</p>
  
  <pre><code>filter_twoArrays(array1,array2)
  
  array2= [grapes, apples, oranges]
  </code></pre>
  
  <p>I've tried the following code, using for loops and array.splice(), but the problem I am seeing is that when I use the splice method, it seems that it changes the lengths of array2 in the for loop:</p>
  
  <pre><code>function filter_twoArrays(filter,result){
  
    for(i=0; i&lt; filter.length; i++){
      for(j=0; j&lt; result.length; j++){
        if(filter[i] !== result[j]){
          result.splice(j,1)
        }
      }
    }
  </code></pre>
  
  <p>Any inputs will be greatly appreciated on how to refine the filter function</p>
  
  <p>cheers!</p>