This commit is contained in:
fallen-angle
2022-05-16 19:55:59 +08:00
parent 7598280fc1
commit 9e3638885d
34 changed files with 3623 additions and 115 deletions

View File

@@ -15,3 +15,24 @@ func Map[T any, V any](arr []T, fun func(item T) V) []V {
}
return res
}
func Distinct[T comparable](arr []T) []T {
set := map[T]interface{}{}
for _, item := range arr {
set[item] = nil
}
var res []T
for k := range set {
res = append(res, k)
}
return res
}
func Contains[T comparable](arr []T, item T) bool {
for _, a := range arr {
if a == item {
return true
}
}
return false
}