Created
June 17, 2022 08:33
-
-
Save huantt/4243a2bfd7ce9bfc3051ec295725e728 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func chunkSlice(slice []int, chunkSize int) [][]int { | |
| var chunks [][]int | |
| for i := 0; i < len(slice); i += chunkSize { | |
| end := i + chunkSize | |
| // necessary check to avoid slicing beyond | |
| // slice capacity | |
| if end > len(slice) { | |
| end = len(slice) | |
| } | |
| chunks = append(chunks, slice[i:end]) | |
| } | |
| return chunks | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment