underscore/intersection.go
Ruidy 1166c701ac
add intersection (#25)
Co-authored-by: Ruidy <rnemausat@newstore.com>
2022-03-27 06:34:09 +02:00

12 lines
315 B
Go

package underscore
// Intersection computes the list of values that are the intersection of all the slices.
// Each value in the result is present in each of the slices.
func Intersection[T comparable](a, b []T) (res []T) {
for _, n := range a {
if Contains(b, n) {
res = append(res, n)
}
}
return res
}