Skip to content

Instantly share code, notes, and snippets.

@edwinlab
Created November 24, 2017 06:50
Show Gist options
  • Select an option

  • Save edwinlab/6af07bc14fba0c7f2c408c66d6be115f to your computer and use it in GitHub Desktop.

Select an option

Save edwinlab/6af07bc14fba0c7f2c408c66d6be115f to your computer and use it in GitHub Desktop.
func split(buf []int, lim int) [][]int {
var chunk []int
chunks := make([][]int, 0, len(buf)/lim+1)
for len(buf) >= lim {
chunk, buf = buf[:lim], buf[lim:]
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:len(buf)])
}
return chunks
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment