array.go
644 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package utils
import (
"strings"
)
type ArrayCmpare interface {
}
//ArrayInt64Diff 返回切片的差集:arr1-arr2
func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 {
if len(arr2) == 0 {
return arr1
}
setmap := make(map[int64]bool)
for i := range arr2 {
setmap[arr1[i]] = true
}
var result []int64
for i := range arr1 {
if _, ok := setmap[arr1[i]]; !ok {
result = append(result, arr1[i])
}
}
return result
}
//ArrayStringIn 检查s字符串是否在切片sl中
func ArrayStringIn(arr1 []string, s string) bool {
for _, v := range arr1 {
if strings.Compare(v, s) == 0 {
return true
}
}
return false
}