Skip to content

Instantly share code, notes, and snippets.

@LiamDotPro
Created December 6, 2016 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LiamDotPro/d82b9e408d7a12bf4a92338cdbbba491 to your computer and use it in GitHub Desktop.
Save LiamDotPro/d82b9e408d7a12bf4a92338cdbbba491 to your computer and use it in GitHub Desktop.
function splitArr (arr, divNum){
tempArr = [];
finalArr = [];
var arrayLength = arr.length;
var counter = 0;
if(arrayLength % divNum === 0){
for(var x = 0; x < divNum; x++ ){
//we need to figure out if
for(var y = counter; y < counter + divNum; y++){
//push the specific instance to the array;
tempArr.push(arr[y]);
counter++;
}
finalArr.push(tempArr);
tempArr = [];
}
} else {
//we know that it is not possible without leftovers or further optimization.
throw new Error();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment