From c1af64854cd9f4d618ef0b5af24a0bc9ae6a4dfb Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 2 Feb 2023 12:00:18 +0800 Subject: [PATCH] 1 --- pkg/utilsv2/slice.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/utilsv2/slice.go b/pkg/utilsv2/slice.go index 96245a276..4aae4c4da 100644 --- a/pkg/utilsv2/slice.go +++ b/pkg/utilsv2/slice.go @@ -25,11 +25,21 @@ func DeleteAt[T any](ts []T, index ...int) []T { case 0: return ts 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:]...) default: tmp := make(map[int]struct{}) - for _, v := range index { - tmp[v] = struct{}{} + for _, i := range index { + if i < 0 { + i = len(ts) + i + } + tmp[i] = struct{}{} } v := make([]T, 0, len(ts)) for i := 0; i < len(ts); i++ {