This commit is contained in:
兔子
2023-05-12 16:34:28 +08:00
parent 677ce0f0c3
commit 21774b777f
3 changed files with 92 additions and 66 deletions

View File

@@ -29,3 +29,25 @@ func ArrayRemove(array []string, args ...string) []string {
}
return array
}
// ArrayUnique - 数组去重
func ArrayUnique[T any](array []T) (slice []any) {
list := make(map[any]bool)
for _, item := range array {
if !list[item] {
list[item] = true
slice = append(slice, item)
}
}
return slice
}
// ArrayEmpty - 数组去空
func ArrayEmpty[T any](array []T) (slice []any) {
for _, item := range array {
if !IsEmpty(item) {
slice = append(slice, item)
}
}
return slice
}