On 3/6/07, Erik Veenstra <erikveen / gmail.com> wrote:
> > Hash[ *a.map{ |o| [ o[:id], o ] }.flatten ].values
>
> Not bad...
>
> How does this ensure that the maximum :w is used?

Hash[ *a.map{ |o| [ o[:id], o ] }.flatten ].values
=> [{:id=>1, :w=>40}, {:id=>2, :w=>20}, {:id=>3, :w=>10}, {:id=>4, :w=>30}]

Hash[*(a.sort_by{|z|z[:id]}).map{|o|[o[:id],o]}.flatten].values
=> [{:id=>1, :w=>40}, {:id=>2, :w=>50}, {:id=>3, :w=>10}, {:id=>4, :w=>60}]