nyitguy nyitguy - 1 month ago 6x
Swift Question

Swift arrays of strings

I have an array of strings.

var animals = ["cats 99", "dogs 42", "chimps 45", "moose 98"]
var excludeAnimalArray = ["chimps", "dogs"]

Output should be "cats 99", "moose 98". Please keep in mind there is no way to tell what the number next to the animal will be.


A shorter filter:

let result = animals.filter { animal in
    !excludeAnimalArray.contains { animal.hasPrefix($0) }