Skip to content

Instantly share code, notes, and snippets.

@ksysctl
Created March 4, 2015 18:02
Show Gist options
  • Save ksysctl/0d9c9e4083e8f5f0b3b1 to your computer and use it in GitHub Desktop.
Save ksysctl/0d9c9e4083e8f5f0b3b1 to your computer and use it in GitHub Desktop.
Split array in n arrays
// 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