Answer the question
In order to leave comments, you need to log in
How to perform a set (array) intersection operation in golang?
Good afternoon!
There are two arrays of different length with variables (well, for example, string)
Is it possible in golang by standard means of an operation that will produce the intersection of these two arrays - variables that are in both arrays?
Answer the question
In order to leave comments, you need to log in
You can make a map[string]int, and make one pass for each array where in each iteration you will increase the value in the map by 1 (where key = word from the array).
As a result, the map will contain keys with a value of 2 - these are intersections, and where 1 - on the contrary, "unique".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question