Sha256: 043afd44e23fe7675fba3c62e4490faa7f0c2e792b1f23c6e51779bbfa19fa93
Contents?: true
Size: 623 Bytes
Versions: 5
Compression:
Stored size: 623 Bytes
Contents
module FootballManager class TeamPicker def self.calculate_fair_teams(players) team_a, team_b = FootballManager::Team.new, FootballManager::Team.new players_in_descending_order(players).each do |player| if team_a.empty? || team_a.points <= team_b.points team_a << player else team_b << player end end return [team_a, team_b] end private def self.players_in_descending_order(players) 5.downto(1).collect do |i| players.select { |player| player.skill == i }.sort_by {rand} end.flatten! end end end
Version data entries
5 entries across 5 versions & 1 rubygems