Containment Containment - 2 months ago 5
Swift Question

How can I filter an array to make sure it does contain positions of another array

I am filtering my array in the following way:

randomArray = randomArray.filter({m in m.x < firstArray[0].x && ConditionX})


I have a another array
secondArray
which contains a elements which are in
randomArray
.
I would like to add another condition (to represent
ConditionX
in the code above) to the filter to remove all positions in
secondArray
from
randomArray

Answer

Despite not understand exactly what you're trying to do here's a swing at basic array filtering.

let array1 = ["a", "b", "c"]
let array2 = ["c", "d", "e"]
var array3 = array1.filter() { return !array2.contains($0) }

That should return:

["a", "b"]