feat: 增加了集合方法 差集、对称差集、交集 (#77)

This commit is contained in:
libin
2024-07-13 16:15:57 +08:00
committed by GitHub
parent 37d3ed1753
commit 9f72a1e7ad
4 changed files with 280 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package sliceUtil
import "fmt"
func ExampleDiff() {
s1 := []int64{1, 2, 5, 7}
s2 := []int64{5, 6, 7}
diff := Diff(s1, s2)
fmt.Println(diff)
// Output:
// [1 2]
}
// 演示 SymmetricDiff 函数的用法
func ExampleSymmetricDiff() {
s1 := []int64{1, 5, 7}
s2 := []int64{5, 6, 7, 8, 9}
s3 := []int64{9, 10, 11}
diff := SymmetricDiff(s1, s2, s3)
fmt.Println(diff)
// Output:
// [1 6 8 10 11]
}
// 演示 ExampleIntersect 函数的用法
func ExampleIntersect() {
s1 := []int64{1, 5, 7}
s2 := []int64{5, 6, 7, 8, 9}
diff := Intersect(s1, s2)
fmt.Println(diff)
// Output:
// [5 7]
}