Skip to content

Instantly share code, notes, and snippets.

@AGhost-7
Created December 31, 2017 17:33
Show Gist options
  • Save AGhost-7/02c45bdc819667992b69726c6fcdb34c to your computer and use it in GitHub Desktop.
Save AGhost-7/02c45bdc819667992b69726c6fcdb34c to your computer and use it in GitHub Desktop.
'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