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

179
Views
¿Cómo puedo generar todos los combos teniendo en cuenta el peso de cada elemento en Javascript?

He estado luchando durante varios días con el siguiente algoritmo que necesito.

Lo que necesito generar son la totalidad de combos teniendo en cuenta el peso en su generación.

 // Generate composition depending on weight. // The weight is a value from 1 to 100, representing the importance in the generation. // ex.: A layer with 1% should only display 1% of the total generated. const layers = [ [ { id: 1, weight: 1 }, // Shows 1 time { id: 2, weight: 9 }, // Shows 9 times { id: 3, weight: 15 }, // Shows 15 times { id: 4, weight: 25 }, // Shows 25 times { id: 5, weight: 50 }, // Shows 50 times ], [ { id: "a", weight: 50 }, // Shows 50 times { id: "b", weight: 25 }, // Shows 25 times { id: "c", weight: 15 }, // Shows 15 times { id: "d", weight: 9 }, // Shows 9 times { id: "e", weight: 1 }, // Shows 1 times ], [ { id: "_", weight: 15 }, // Shows 15 times { id: "-", weight: 25 }, // Shows 25 times { id: ".", weight: 50 }, // Shows 50 times { id: ",", weight: 9 }, // Shows 9 times ] // ... There could be more collections ] const combTotal = layers[0].length * layers[1].length * layers[2].length // => 100 // Expect result: [ [5, "d", "."], [2, "a", "_"], [4, "a", ","], // ... ]

Generar toda la composición sin pesos es sencillo, pero el cálculo para tener en cuenta el peso me está costando más de lo debido.

Si alguien pudiera mostrarme alguna referencia para desbloquearme, sería genial.

Saludos

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!