I am new to Javascript and need some help. I have an array of people that can change in length. I am trying to break into pairs and assign it a number. I then would like to use that number to create the groups based on the lowest number. Originally everyone will start off at zero and the groups of four will be randomly created.
I am able to break down the array of people into pairs, but am having a hard time trying to assign it a number. So far I have something like this:
let groupResults = []
let groupPairs = {
people: [],
value: {},
}
const buildGroups = (array, num) => {
for (let i = 0; i < array.length - 1; i++) {
for (let j = i + 1; j < array.length; j++) {
groupResults.push(`${array[i]} & ${array[j]}`)
}
}
return groupResults
}
const storingGroups = buildGroups(groups)
groupPairs = storingGroups.map((p, value) => ({ people: [p], value }))
This is breaking down the groups into pairs the way I want but I am having a hard time with the value. My goal is to have groups of of these people to be created based on the lowest value or probability. Something like this seems to work but I am having a hard time storing the value from it in the "groupPairs" object
let counts = {};
mappedValues.forEach(x => { counts[x] = (counts[x] || 0) + 1 })
Thanks in advance for any help