Home > database >  how to compare two array and remove the same values by swift?
how to compare two array and remove the same values by swift?

Time:10-17

var string1 = ["A", "B", "C"] var string2 = ["B"]

how to get the following result? Thanks so much!

var result = ["A","C"]

CodePudding user response:

You can use a filter to filter out any elements in string1 that are contained in string2:

let result = string1.filter { !string2.contains($0) }
  • Related