1 Star 0 Fork 0

danlansky/go-library

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
array.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
zhangminghua 提交于 11个月前 . feat:基础工具包
package utils
import "sort"
/**
* slice(string类型)元素去重
*/
func RemoveReplicaSliceString(slc []string) []string {
result := make([]string, 0)
tempMap := make(map[string]bool, len(slc))
for _, e := range slc {
if tempMap[e] == false {
tempMap[e] = true
result = append(result, e)
}
}
return result
}
/**
* slice(int类型)元素去重
*/
func RemoveReplicaSliceInt(slc []int) []int {
result := make([]int, 0)
tempMap := make(map[int]bool, len(slc))
for _, e := range slc {
if tempMap[e] == false {
tempMap[e] = true
result = append(result, e)
}
}
return result
}
// CompareIntSlice 比较两个int型切片是否相等, true:相等, false:不相等
func CompareIntSlice(a, b []int) bool {
if len(a) != len(b) {
return false
}
if (a == nil) != (b == nil) {
return false
}
sort.Ints(a[:])
sort.Ints(b[:])
for key, value := range a {
if value != b[key] {
return false
}
}
return true
}
//值是否存在
func IsSliceString(val string, slice []string) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
//值是否存在
func IsSliceInt64(val int64, slice []int64) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
func IsSliceInt(val int, slice []int) bool {
if len(slice) == 0 {
return false
}
for _, item := range slice {
if item == val {
return true
}
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/danlansky/go-library.git
git@gitee.com:danlansky/go-library.git
danlansky
go-library
go-library
v1.0.7

搜索帮助