From 29fd5a25d2cb73575928c1df639f2564ee82c85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=92=8B=E5=B0=8F=E5=B0=8F?= Date: Sat, 20 Apr 2024 17:33:19 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A9=BA=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=88=86=E9=9A=94=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 蒋小小 --- server/pkg/utils/collx/array.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/server/pkg/utils/collx/array.go b/server/pkg/utils/collx/array.go index 180612bd..84e7deef 100644 --- a/server/pkg/utils/collx/array.go +++ b/server/pkg/utils/collx/array.go @@ -93,9 +93,13 @@ func ArraySplit[T any](arr []T, numGroups int) [][]T { numGroups = len(arr) } + arrayLen := len(arr) + if arrayLen < 1 { + return [][]T{} + } // 计算每个子数组的大小 - size := len(arr) / numGroups - remainder := len(arr) % numGroups + size := arrayLen / numGroups + remainder := arrayLen % numGroups // 创建一个存放子数组的切片 subArrays := make([][]T, numGroups)