How do I get the intersection between two arrays as a new array?
- Simple Intersection: Compare each element in
A
to each inB
(O(n^2)
) - Hash Intersection: Put them into a hash table (
O(n)
) - Sorted Intersection: Sort
A
and do an optimized intersection (O(n*log(n))
)
All of which are implemented here
https://github.com/juliangruber/go-intersect/blob/master/intersect.go