Skip to content

Instantly share code, notes, and snippets.

@clarkmcc
Created January 13, 2020 22:34
Show Gist options
  • Save clarkmcc/b16eec9368a4ddfb7491bf9bc36bae85 to your computer and use it in GitHub Desktop.
Save clarkmcc/b16eec9368a4ddfb7491bf9bc36bae85 to your computer and use it in GitHub Desktop.
Accepts a slice of strings and returns a slice of slices of strings where each child slices's length is the length of the size parameter
package util
// Accepts a slice of strings and returns a slice of slices of strings where each child slices's length
// is the length of the batchSize
func StringBatch(size int, s []string) [][]string {
var b [][]string
for size < len(s) {
s, b = s[size:], append(b, s[0:size:size])
}
b = append(b, s)
return b
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment