array.go
606 字节
package utils
import (
"strings"
)
type ArrayCmpare interface {
}
//ArrayInt64Diff 返回切片的差集:arr1-arr2
func ArrayInt64Diff(arr1 []int64, arr2 []int64) []int64 {
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
}