Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
probability algorithm for creating groups

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!