Created
December 6, 2016 16:54
-
-
Save LiamDotPro/d82b9e408d7a12bf4a92338cdbbba491 to your computer and use it in GitHub Desktop.
This file contains 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 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