Created
May 15, 2018 08:07
-
-
Save larryyangsen/a5d096d8772a2e0df7c81189243c632b to your computer and use it in GitHub Desktop.
group array
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
func groupArray(array []int, length int) [][]int { | |
var group [][]int | |
if length > len(array) { | |
return nil | |
} | |
for len(array) > length { | |
var newArray []int | |
newArray = append(newArray, array[:length]...) | |
group = append(group, newArray) | |
array = append(array[:0], array[length:]...) | |
} | |
group = append(group, array) | |
return group | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment