Files
hucan f3ca87fb54
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
1、在线支付
2、查询平台剩余字符数
2025-07-07 19:01:54 +08:00

40 lines
804 B
Go

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
}
func ContainsString(arr []string, v string) bool {
for _, a := range arr {
if a == v {
return true
}
}
return false
}