Created
March 4, 2015 18:02
-
-
Save ksysctl/0d9c9e4083e8f5f0b3b1 to your computer and use it in GitHub Desktop.
Split array in n arrays
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
// l: iterable | |
// n: number of arrays to obtain | |
var splitter = function(l, n) { | |
var m = l.length / n, j = 0, k = m, s = []; | |
for (i = 0; i < n; i++) { | |
s.push(l.slice(j, k)); | |
j = j + m; | |
k = k + m; | |
} | |
return s; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment