This commit is contained in:
withchao 2023-02-02 12:00:18 +08:00
parent dab552aed4
commit c1af64854c

View File

@ -25,11 +25,21 @@ func DeleteAt[T any](ts []T, index ...int) []T {
case 0: case 0:
return ts return ts
case 1: case 1:
i := index[0]
if len(ts) <= i || len(ts) < -i {
return ts
}
if i < 0 {
i = len(ts) + i
}
return append(ts[:index[0]], ts[index[0]+1:]...) return append(ts[:index[0]], ts[index[0]+1:]...)
default: default:
tmp := make(map[int]struct{}) tmp := make(map[int]struct{})
for _, v := range index { for _, i := range index {
tmp[v] = struct{}{} if i < 0 {
i = len(ts) + i
}
tmp[i] = struct{}{}
} }
v := make([]T, 0, len(ts)) v := make([]T, 0, len(ts))
for i := 0; i < len(ts); i++ { for i := 0; i < len(ts); i++ {