Skip to content

Instantly share code, notes, and snippets.

@garystorey
Last active August 16, 2018 19:26
Show Gist options
  • Save garystorey/dd9b2167cc56fce9f7f80bb16339a497 to your computer and use it in GitHub Desktop.
Save garystorey/dd9b2167cc56fce9f7f80bb16339a497 to your computer and use it in GitHub Desktop.
Splits a given array <arr> into an array of arrays of <size> size. Ex: splitter([1,2,3,4,5], 2) // [[1,2],[3,4],[5]]
function splitter(arr,size) {
var i,j,temparray=[], splitarray=[];
for (i=0,j=arr.length; i<j; i+=size) {
temparray = arr.slice(i,i+size);
splitarray.push(temparray);
}
return splitarray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment