Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

104
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda