Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
array.sort() - how to get very uneven distribution?

I'm trying to remove random elements from a list of cartesian combinations of values,
so that it affects the items in a less even way.

So that for example some items do not exist anymore, or in very low quantities, while others keep their numbers.

but although I'm dropping 200+ items from the total of 625 items, no single items ever gets a distribution lower than around ~70.

I would have expected for some items completely disappear, or at least get a lot less distributed.

How do you achieve a more uneven distribution?

base = [
  ['a1', 'a2', 'a3', 'a4', 'a5'],
  ['b1', 'b2', 'b3', 'b4', 'b5'],
  ['c1', 'c2', 'c3', 'c4', 'c5'],
  ['d1', 'd2', 'd3', 'd4', 'd5'],
]

const cartesian = (...a) => a.reduce((a, b) => a.flatMap(d => b.map(e => [d, e].flat())))

const countDistributions = output => {
  const counts = {}
  output.forEach(item => {
    item.forEach(letter => {
      counts[letter] = (counts[letter] || 0) + 1
    })
  })
  return counts
}

const output = cartesian(...base)
console.log(countDistributions(output))

output.sort(() => Math.random() - 0.5)
const dropSize = output.length / 3
truncatedOutput = output.slice(0, output.length - dropSize)
console.log(countDistributions(truncatedOutput))

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda