Created
December 31, 2017 17:33
-
-
Save AGhost-7/02c45bdc819667992b69726c6fcdb34c 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
'use strict' | |
const _ = require('lodash') | |
const teams = _.range(1, 20) | |
const chunkSize = 5 | |
const {groupings} = _(teams) | |
.map((team) => ({ number: team, order: Math.random() })) | |
.sortBy('order') | |
.reduce(({ groupings, chunk }, { number, order }) => { | |
groupings[groupings.length - 1].push(number) | |
if(chunk >= chunkSize) { | |
groupings.push([]) | |
return { groupings, chunk: 0 } | |
} else { | |
chunk += 1 | |
return { groupings, chunk } | |
} | |
}, { groupings: [[]], chunk: 0 }) | |
console.log(groupings) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment