We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 0d500fd commit be012a1Copy full SHA for be012a1
helpers/chumk.go arrays/chunk.go
@@ -1,14 +1,15 @@
1
-package helpers
+package arrays
2
3
// Chunk will take a slice of any kind and a chunk size and return a slice of slices
4
func Chunk[T any](arr []T, chunkSize int) [][]T {
5
- var chunks [][]T
+ chunks := [][]T{}
6
for i := 0; i < len(arr); i += chunkSize {
7
end := i + chunkSize
8
if end > len(arr) {
9
end = len(arr)
10
}
11
chunks = append(chunks, arr[i:end])
12
13
+
14
return chunks
15
0 commit comments