Skip to content

Commit

Permalink
new util function
Browse files Browse the repository at this point in the history
  • Loading branch information
jm33-m0 committed Sep 21, 2023
1 parent 4eeacf6 commit 9c1daa1
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/lib/util/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down

0 comments on commit 9c1daa1

Please sign in to comment.