From e95f609c0f735998c75684be7abe5f3db78ec0e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 23 Jul 2022 21:15:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- string.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 +}