字符串列表去重能力

This commit is contained in:
白茶清欢 2022-07-23 21:15:33 +08:00
parent 29b0f171ff
commit e95f609c0f

View File

@ -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
}