To generate two random arrays in Swift, we can use the following code:
main.swift127 chars3 lines
This code generates two arrays of length 10 with elements randomly chosen from 0 to 100.
To find the matching numbers in the two arrays, we can use a simple loop and an array intersection operation like this:
main.swift174 chars10 lines
Here, we loop through the elements of the first array, check if they exist in the second array, and add them to a matches
array if they do. We also check that the number is not already in the matches
array to avoid duplicates.
The matches
array will contain all the numbers that are present in both arrays.
gistlibby LogSnag