From 9c1daa133df743c1d1585937e6e753708bcd75b0 Mon Sep 17 00:00:00 2001 From: jm33-m0 Date: Thu, 21 Sep 2023 17:33:05 +0800 Subject: [PATCH] new util function --- core/lib/util/file.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/lib/util/file.go b/core/lib/util/file.go index c6ef851c7..50f121bfd 100644 --- a/core/lib/util/file.go +++ b/core/lib/util/file.go @@ -108,6 +108,17 @@ func IsDirExist(path string) bool { return false } +// RemoveItemFromArray remove string/int from slice +func RemoveItemFromArray[T string | int](to_remove T, sliceList []T) []T { + list := []T{} + for _, item := range sliceList { + if item != to_remove { + list = append(list, item) + } + } + return list +} + // RemoveDupsFromArray remove duplicated string/int from slice func RemoveDupsFromArray[T string | int](sliceList []T) []T { allKeys := make(map[T]bool) @@ -116,9 +127,7 @@ func RemoveDupsFromArray[T string | int](sliceList []T) []T { if _, value := allKeys[item]; !value { allKeys[item] = true list = append(list, item) - } - } return list }