-
-
Save ehsansabet/38519ed18966b964e64000cebbc75420 to your computer and use it in GitHub Desktop.
Go / Chunk Slice
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
# https://play.golang.org/p/JxqibtHkuO- | |
func chunkBy(items []string, chunkSize int) (chunks [][]string) { | |
for chunkSize < len(items) { | |
items, chunks = items[chunkSize:], append(chunks, items[0:chunkSize:chunkSize]) | |
} | |
return append(chunks, items) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment