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"])