array.go 1002 字节
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[arr2[i]] = true
	}
	var result []int64
	for i := range arr1 {
		if _, ok := setmap[arr1[i]]; !ok {
			result = append(result, arr1[i])
		}
	}

	return result
}

//ArrayIntDiff 返回切片的差集:arr1-arr2
func ArrayIntDiff(arr1 []int, arr2 []int) []int {
	if len(arr2) == 0 {
		return arr1
	}
	setmap := make(map[int]bool)
	for i := range arr2 {
		setmap[arr2[i]] = true
	}
	var result []int
	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
}