mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-10-13 13:33:44 +08:00
v2.0
This commit is contained in:
46
server/utility/convert/convert.go
Normal file
46
server/utility/convert/convert.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// Package convert
|
||||
// @Link https://github.com/bufanyun/hotgo
|
||||
// @Copyright Copyright (c) 2022 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package convert
|
||||
|
||||
// UniqueSliceInt64 切片去重
|
||||
func UniqueSliceInt64(languages []int64) []int64 {
|
||||
result := make([]int64, 0, len(languages))
|
||||
temp := map[int64]struct{}{}
|
||||
for _, item := range languages {
|
||||
if _, ok := temp[item]; !ok { //如果字典中找不到元素,ok=false,!ok为true,就往切片中append元素。
|
||||
temp[item] = struct{}{}
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// InSliceInt64 元素是否存在于切片中
|
||||
func InSliceInt64(slice []int64, key int64) bool {
|
||||
if len(slice) == 0 {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(slice); i++ {
|
||||
if slice[i] == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// InSliceInt 元素是否存在于切片中
|
||||
func InSliceInt(slice []int, key int) bool {
|
||||
if len(slice) == 0 {
|
||||
return false
|
||||
}
|
||||
for i := 0; i < len(slice); i++ {
|
||||
if slice[i] == key {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Reference in New Issue
Block a user