Skip to content

Commit

Permalink
common: Improve SliceDifference
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Sep 12, 2024
1 parent 66f4770 commit 860b803
Showing 1 changed file with 0 additions and 4 deletions.
4 changes: 0 additions & 4 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,12 @@ func NewHTTPClientWithTimeout(t time.Duration) *http.Client {
// SliceDifference returns the elements that are in slice1 or slice2 but not in both
func SliceDifference[T comparable](slice1, slice2 []T) []T {
diff := make([]T, 0, len(slice1)+len(slice2))
target := 0
for x := range slice1 {
if !slices.Contains(slice2, slice1[x]) {
diff = append(diff, slice1[x])
continue
}
slice1[target] = slice1[x]
target++
}
slice1 = slice1[:target]
for x := range slice2 {
if !slices.Contains(slice1, slice2[x]) {
diff = append(diff, slice2[x])
Expand Down

0 comments on commit 860b803

Please sign in to comment.