1
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
Issue Check Inactive / issue-check-inactive (push) Has been cancelled
Some checks failed
Build / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
build / Build (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitee (push) Has been cancelled
GitHub Actions Mirror / mirror_to_gitlab (push) Has been cancelled
Issue Close Require / issue-close-require (push) Has been cancelled
Issue Check Inactive / issue-check-inactive (push) Has been cancelled
This commit is contained in:
29
utils/utility/slice.go
Normal file
29
utils/utility/slice.go
Normal file
@ -0,0 +1,29 @@
|
||||
package utility
|
||||
|
||||
// SplitSlice 将 []string 切片根据最大数量分割成二维数组
|
||||
func SplitSlice[T any](slice []T, maxSize int) [][]T {
|
||||
var result [][]T
|
||||
|
||||
// 遍历切片,每次取 maxSize 个元素
|
||||
for i := 0; i < len(slice); i += maxSize {
|
||||
end := i + maxSize
|
||||
// 如果 end 超出切片长度,则取到切片末尾
|
||||
if end > len(slice) {
|
||||
end = len(slice)
|
||||
}
|
||||
// 将当前段添加到结果中
|
||||
result = append(result, slice[i:end])
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// ContainsInt []int 包含元素?
|
||||
func ContainsInt(arr []int, v int) bool {
|
||||
for _, a := range arr {
|
||||
if a == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user