Skip to content

Instantly share code, notes, and snippets.

@SauloSilva
Created October 2, 2013 04:02
Show Gist options
  • Save SauloSilva/6788986 to your computer and use it in GitHub Desktop.
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]]
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