You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
301 B
Go

package main
import "slices"
// Returns all elements in slice A that are NOT in slice B
func setDifference[T comparable](s1 []T, s2 []T) []T {
toReturn := make([]T, 0, len(s1))
for _, val := range s1 {
if !slices.Contains(s2, val) {
toReturn = append(toReturn, val)
}
}
return toReturn
}