1 Star 0 Fork 0

chuanwan / utils-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
string.go 665 Bytes
一键复制 编辑 原始数据 按行查看 历史
wanchuan 提交于 2023-03-20 19:25 . Difference
package utils
// Difference returns the difference array between two arrays.
func Difference(slice1 []string, slice2 []string) []string {
var diff []string
// Loop two times, first to find slice1 strings not in slice2,
// second loop to find slice2 strings not in slice1
for i := 0; i < 2; i++ {
for _, s1 := range slice1 {
found := false
for _, s2 := range slice2 {
if s1 == s2 {
found = true
break
}
}
// String not found. We add it to return slice
if !found {
diff = append(diff, s1)
}
}
// Swap the slices, only if it was the first loop
if i == 0 {
slice1, slice2 = slice2, slice1
}
}
return diff
}
1
https://gitee.com/chuanwan/utils-go.git
git@gitee.com:chuanwan/utils-go.git
chuanwan
utils-go
utils-go
56721df46a4f

搜索帮助