Skip to content

Instantly share code, notes, and snippets.

@zgiber
Created February 21, 2018 16:13
Show Gist options
  • Save zgiber/8ab01c5abfe329e1ab12c184fc22808f to your computer and use it in GitHub Desktop.
Save zgiber/8ab01c5abfe329e1ab12c184fc22808f to your computer and use it in GitHub Desktop.
slice up
func sliceUp(s []string, size int) [][]string {
total := len(s)
var result [][]string
for i := 0; ; i++ {
first := size * i
if first > total {
break
}
last := size * (i + 1)
if last > total {
last = total
}
result = append(result, s[first:last])
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment