iOS swift remove elements of an array from another array

前端 未结 6 851
有刺的猬
有刺的猬 2020-12-13 12:24

I have two arrays

var array1 = new Array [\"a\", \"b\", \"c\", \"d\", \"e\"]
var array2 = new Array [\"a\", \"c\", \"d\"]

I want to remove

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 12:25

    You can create sets and then use the subtract method

    let setA = Set(arr1)
    let setB = Set(arr2)
    setA.subtract(setB)
    

提交回复
热议问题