I have two string arrays with unique amounts of content and data in each.
I want to be able to find the count of the number of items that appear in both arrays.
Example:
var array1 = ["Duck", "Dog", "Cat", "Bird", "Elephant", "Cow", "Goat", "Goose"]
var array2 = ["Eagle", "Giraffe", "Cow", "Elephant", "Sheep", "Penguin", "Rhinoceros"]
This should print 2, because Cow and Elephant appear in both array1 and array2.
My progress is below. This is throwing an error: Closure tuple parameter '(offset: Int, element: (String, String))' does not support destructuring with implicit parameters
let compared = zip(array1, array2).enumerated().filter() {
$1.0.id == $1.1.id
}.count
print(compared)
How do I find the count of items that appear in both arrays? Note, there will never be 3 or more arrays. Always will compare 2 arrays.