Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions intersect.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func Intersect[T comparable, Slice ~[]T](list1 Slice, list2 Slice) Slice {
for i := range list2 {
if _, ok := seen[list2[i]]; ok {
result = append(result, list2[i])
delete(seen, list2[i])
}
}

Expand Down
2 changes: 2 additions & 0 deletions intersect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@ func TestIntersect(t *testing.T) {
result3 := Intersect([]int{0, 1, 2, 3, 4, 5}, []int{-1, 6})
result4 := Intersect([]int{0, 6}, []int{0, 1, 2, 3, 4, 5})
result5 := Intersect([]int{0, 6, 0}, []int{0, 1, 2, 3, 4, 5})
result6 := Intersect([]int{0, 1, 2, 3, 4, 5}, []int{0, 1, 1})

is.Equal(result1, []int{0, 2})
is.Equal(result2, []int{0})
is.Equal(result3, []int{})
is.Equal(result4, []int{0})
is.Equal(result5, []int{0})
is.Equal(result6, []int{0, 1})

type myStrings []string
allStrings := myStrings{"", "foo", "bar"}
Expand Down