34 lines
553 B
Go
34 lines
553 B
Go
package utils
|
|
|
|
func SliceContains[T comparable](s []T, e T) bool {
|
|
for _, a := range s {
|
|
if a == e {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func SliceEqual[T comparable](a, b []T) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
for i, v := range a {
|
|
if v != b[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func RemoveDuplicates[T comparable](slice []T) (result []T) {
|
|
set := make(map[T]struct{})
|
|
for _, item := range slice {
|
|
if _, exists := set[item]; !exists {
|
|
set[item] = struct{}{}
|
|
result = append(result, item)
|
|
}
|
|
}
|
|
return result
|
|
}
|