🎨 Update av

This commit is contained in:
Daniel 2023-07-03 20:12:07 +08:00
parent b6f62eb4ea
commit ad70e42fd6
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 19 additions and 5 deletions

View file

@ -24,9 +24,21 @@ import (
"github.com/88250/lute/html"
)
// InsertElement inserts a new element value at the specified index position.
// RemoveDuplicatedElem removes the duplicated elements from the slice.
func RemoveDuplicatedElem(slice []int) (ret []int) {
allKeys := make(map[int]bool)
for _, item := range slice {
if _, value := allKeys[item]; !value {
allKeys[item] = true
ret = append(ret, item)
}
}
return
}
// InsertElem inserts a new element value at the specified index position.
// 0 <= index <= len(a)
func InsertElement[T any](ret []T, index int, value T) []T {
func InsertElem[T any](ret []T, index int, value T) []T {
if len(ret) == index { // nil or empty slice or after last element
return append(ret, value)
}