Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const splitArray = (inArray, buckets) => {
return inArray.reduce((retArr, value, index) => {
const bucket = index % buckets;
if (!retArr[bucket]) {
retArr[bucket] = [];
}
retArr[bucket].push(value)
return retArr
}, [[]]);
}
const arr = 'ABCFEFGHIJKLMNOPQRSTUVWXYZ'.split('');
const splitted = splitArray(arr, 3);
/*
output:
[
[
"A",
"F",
"G",
"J",
"M",
"P",
"S",
"V",
"Y"
],
[
"B",
"E",
"H",
"K",
"N",
"Q",
"T",
"W",
"Z"
],
[
"C",
"F",
"I",
"L",
"O",
"R",
"U",
"X"
]
]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.