字符串列表去重能力
This commit is contained in:
parent
29b0f171ff
commit
e95f609c0f
21
string.go
21
string.go
@ -112,3 +112,24 @@ func (s *stringOperate) Convert(str string, sourceCode string, targetCode string
|
||||
_, cdata, _ := targetCoder.Translate([]byte(sourceResult), true)
|
||||
return string(cdata)
|
||||
}
|
||||
|
||||
// RemoveDuplicates 对列表数据去重
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 21:12 2022/7/23
|
||||
func (s *stringOperate) RemoveDuplicates(sourceList []string) []string {
|
||||
result := make([]string, 0)
|
||||
hasDeal := make(map[string]bool)
|
||||
if len(sourceList) == 0 {
|
||||
return result
|
||||
}
|
||||
for _, val := range sourceList {
|
||||
if _, exist := hasDeal[val]; exist {
|
||||
continue
|
||||
}
|
||||
result = append(result, val)
|
||||
hasDeal[val] = true
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user