Created
October 2, 2013 04:02
-
-
Save SauloSilva/6788986 to your computer and use it in GitHub Desktop.
split array in js. Ex: [1,2,3,4,5,6,7] by 2 transform to [[1,2], [3,4], [5,6], [7]]
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
split = (array, numberOf) -> | |
matrix = [] | |
indice = 0 | |
aux = -1 | |
while indice < array.length | |
if indice % numberOf is 0 | |
aux++ | |
matrix[aux] = [] | |
matrix[aux].push array[indice] | |
indice++ | |
matrix |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment