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

164
Vistas
How to match array of values to another array of traits?

I need to divide a list of unique traits (for example ["Top","Middle","Bottom"], three of five traits) between sets of different percentages that describe the traits, looking like this:

[
  [
    4.545454545454546,
    4.545454545454546,
    27.27272727272727,
    27.27272727272727,
    36.36363636363637
  ],
  [
    13.043478260869565,
    8.695652173913043,
    26.08695652173913,
    34.78260869565217,
    17.391304347826086
  ],
  [
    33.33333333333333,
    16.666666666666664,
    33.33333333333333,
    0,
    16.666666666666664
  ]
]

where each index of such a set

[
    33.33333333333333,
    16.666666666666664,
    33.33333333333333,
    0,
    16.666666666666664
]

describes the percentage for one of the five traits.

Now I can't just compare for each trait the values with e.g. an Math.max(), cause if there are the same percentages (which is in fact very likely), it can't select randomly, but has to compare the remaining traits, to match the traits to the percentages accordingly. And I just can't think of a way to have this remaining trait comparison.

Edit: An expected output would be, given the traits ["Top","Middle","Bottom"] corresponding to the first three values and the values of the above example [2,1,0]. Where in this array the index matches the trait index and the value the index of the value set. In this case set 3, index 2, would get the trait top, as it has the highest top-value and no other set has a high top value, set 2 the middle value, as its bottom value is lower than the first sets value, and the first set would be bottom, as it has the highest bottom value compared to the other values.

Edit 2: Expected input:

Traits that should be compared: ["Top","Middle","Bottom"]

Input sets of values:

[
  [
    4.545454545454546,
    4.545454545454546,
    27.27272727272727,
    27.27272727272727, // given but not needed, as only the first three traits a relevant in this case
    36.36363636363637 // given but not needed
  ],
  [
    13.043478260869565,
    8.695652173913043,
    26.08695652173913,
    34.78260869565217, // given but not needed
    17.391304347826086 // given but not needed
  ],
  [
    33.33333333333333,
    16.666666666666664,
    33.33333333333333,
    0, // given but not needed
    16.666666666666664 // given but not needed
  ]
]

Expected output:

Distribution of traits across value sets: [2,1,0] (corresponding to ["Top","Middle","Bottom"])

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