X-Git-Url: https://projects.mako.cc/source/selectricity/blobdiff_plain/6a1c545f073430dd46bf5ad89b0450a16c659b00..ce1489ae318bfe129070ecaf4e5c422015572caf:/lib/rubyvote/condorcet.rb diff --git a/lib/rubyvote/condorcet.rb b/lib/rubyvote/condorcet.rb index 0cc1696..0c6fd56 100644 --- a/lib/rubyvote/condorcet.rb +++ b/lib/rubyvote/condorcet.rb @@ -123,27 +123,18 @@ class CondorcetResult < ElectionResult end def victories_and_ties - victors = Array.new - victories_ties = Hash.new + victories_ties = {} candidates = @matrix.keys.sort candidates.each do |candidate| candidates.each do |challenger| next if candidate == challenger diff = @matrix[candidate][challenger] - @matrix[challenger][candidate] - if diff >= 0 - victors << [candidate, challenger, diff] + victories_ties[candidate] = {} unless victories_ties.key?(candidate) + if diff >= 0 + victories_ties[candidate][challenger] = diff end end - end - - victors.each do |list| - if victories_ties.has_key?(list[0]) - victories_ties[list[0]][list[1]] = list[2] - else - victories_ties[list[0]] = Hash.new - victories_ties[list[0]][list[1]] = list[2] - end end return victories_ties