L
L
levisl2015-09-04 18:20:23
go
levisl, 2015-09-04 18:20:23

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

2 answer(s)
L
lega, 2015-09-07
@lelvisl

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".

K
Kirill, 2015-09-04
@kshvakov

no, but it's easy to write it yourself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question