Created
February 21, 2018 16:13
-
-
Save zgiber/8ab01c5abfe329e1ab12c184fc22808f to your computer and use it in GitHub Desktop.
slice up
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 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