From: "David A. Black" Date: 2009-09-27T00:54:13+09:00 Subject: Re: How to remove duplicate elements in a 2D array Hi -- On Sun, 27 Sep 2009, Rick DeNatale wrote: > I like David Black's alternative suggestion: > > result = arr.inject({}){|x,y| x[y[0]]=y; x}.values > > Note that neither of these preserve the ordering of the rows retained > from the original array in Ruby 1.8.x, but if you're happy I guess > that's not a requirement. And in 1.9, you can do this: arr.map.with_object({}) {|e,h| h[e[0]] = e }.values which gets rid of the need to force the accumulator to be the hash every time through. David -- David A. Black, Director Ruby Power and Light, LLC (http://www.rubypal.com) Ruby/Rails training, consulting, mentoring, code review Book: The Well-Grounded Rubyist (http://www.manning.com/black2)