Last active
August 16, 2018 19:26
-
-
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]]
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
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