Created
March 9, 2014 00:46
-
-
Save onestepcreative/9441335 to your computer and use it in GitHub Desktop.
helper function to quickly break up array into smaller equal size arrays
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 chunkitup(arr, chunks) { | |
| var len = arr.length; | |
| var out = []; | |
| var i = 0; | |
| while (i < len) { | |
| var chunkSize = Math.ceil((len - i) / chunks--); | |
| out.push(arr.slice(i, i + chunkSize)); | |
| i += chunkSize; | |
| } | |
| return out; | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment