mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-02 06:48:49 +01:00
♻️ 从切片中删除重复项时保留顺序
This commit is contained in:
parent
5c0525c359
commit
39d0a9b08f
1 changed files with 6 additions and 7 deletions
|
|
@ -38,13 +38,12 @@ func ExcludeElem(slice, excludes []string) (ret []string) {
|
|||
}
|
||||
|
||||
func RemoveDuplicatedElem(slice []string) (ret []string) {
|
||||
m := map[string]bool{}
|
||||
for _, str := range slice {
|
||||
m[str] = true
|
||||
}
|
||||
ret = []string{}
|
||||
for str, _ := range m {
|
||||
ret = append(ret, str)
|
||||
allKeys := make(map[string]bool)
|
||||
for _, item := range slice {
|
||||
if _, value := allKeys[item]; !value {
|
||||
allKeys[item] = true
|
||||
ret = append(ret, item)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue