Reputation: 93
I need to find all objects, which contains in first and second arrays. I have this code, which works fine:
let items = catalog.items.filter({ (item) -> Bool in
orderItems.contains { $0.id == item.id }
})
But I want to reduce that it will look like:
catalog.items.filter{items.contains{ $0.id == first.id }}
where first.id - is element from catalog.items. How can I do it?))
Upvotes: 1
Views: 113
Reputation: 1509
Single line solution:
catalog.items.filter { item in orderItems.contains { $0.id == item.id }}
Upvotes: 1