I have an input that is a list of players:
[
%{rating: 8, member_id: 1},
%{rating: 5, member_id: 4},
%{rating: 6, member_id: 2},
%{rating: 7, member_id: 3}
]
I then want to divide them into two teams that would look like this:
[%{team_id: 0, members: []}, %{team_id: 1, members: []}]
The team with the least amount of players picks first; if there is a tie then the team with the lowest summed rating of members picks. The team will always pick the first in the player list that hasn’t already been picked.
So team 1 would pick member id 1, then team 2 would pick member id 4, then team 2 would pick member id 2, then team 1 would pick member id 3.
My first thought is to use Map.reduce with
[%{team_id: 0, members: []}, %{team_id: 1, members: []}]
as the accumulator. But not sure how to update it.