Assuming roleConfigs is an array of role configurations that scale with the player quantity that is used to determine the average ratio of roles per game.
roleConfigs.map(({ roles, playerCount }) => {
return roles.map(({ role, count }) => ({
role, ratio: count / playerCount
}))
}).reduce((prev, next) => {
return next.map(({ role, ratio }, index) => {
return { role, ratio: (prev[index]?.ratio || 0) + ratio }
});
}, []).map(({ role, ratio }, index, array) => ({ role, ratio: ratio / array.length }));
The following assumes that the sum of count found in each role is equal to that of playerCount for that particular configuration - which is then used to determine the ratio of roles for that game, and then again with the output of that result to determine an average.
The following assumes that the sum of
countfound in eachroleis equal to that ofplayerCountfor that particular configuration - which is then used to determine the ratio of roles for that game, and then again with the output of that result to determine an average.