Created
January 13, 2020 22:34
-
-
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
This file contains 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
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