diff --git a/string.go b/string.go index 9358b96..f05d0f7 100644 --- a/string.go +++ b/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 +}