Created
September 29, 2018 08:04
-
-
Save fondberg/7a099255cbb16ea453218651d871b19f to your computer and use it in GitHub Desktop.
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
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