title: Swift Filtering array elements
body: <p>I am creating a function that will filter an array, <br>e.g.
  x = [10,20,30,40,50]<br>
  filter(x,10,20) <br>
  output should be 30,40,50.<br>
  I am getting an index out of bounds error .
  Here's my code: <br></p>
  
  <pre><code>func filterArray( _ x:  [Int], _ nums: Int...) -&gt; [Int]{
  var arrayX = x
      for i in 0...arrayX.count-1{
          for j in 0...nums.count-1 {
              if arrayX[i] == nums[j]{//Changed arrayX to x because x was never changed
               if let index = arrayX.index(of: nums[j]) {
                      arrayX.remove(at: index) //error is here
                  }
                  else{
  
                  }
              }
          }
      }
      return arrayX
  }
  
  var mArray = [10,20,30,40,50]
  filterArray(mArray,10)
  </code></pre>