finish
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user