From 7bb7c030c1a7b1eeb45334128cbb450045a8d191 Mon Sep 17 00:00:00 2001 From: tiglog Date: Tue, 31 Oct 2023 16:21:01 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=E5=88=87=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helper/slice_helper.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/helper/slice_helper.go b/helper/slice_helper.go index 9ce4ca6..183fee8 100644 --- a/helper/slice_helper.go +++ b/helper/slice_helper.go @@ -39,3 +39,36 @@ func IsIntSlice(v interface{}) bool { _, ok := v.([]int) return ok } + +func DeleteIntSlice(a []int, elt int) []int { + var size = len(a) + for i := 0; i < size; i++ { + if a[i] == elt { + a = append(a[:i], a[i+1:]...) + i-- + } + } + return a +} + +func DeleteStrSlice(a []string, elt string) []string { + var size = len(a) + for i := 0; i < size; i++ { + if a[i] == elt { + a = append(a[:i], a[i+1:]...) + i-- + } + } + return a +} + +func DeleteSlice(a []any, elt any) []any { + var size = len(a) + for i := 0; i < size; i++ { + if a[i] == elt { + a = append(a[:i], a[i+1:]...) + i-- + } + } + return a +}