Hi --

On Sun, 27 Sep 2009, pharrington wrote:

>> r.map {|x| x.first if x.first == e.first}.compact.size == 0
>
> I'm an idiot, Ruby likes to call this pile of silliness "detect":
>
> arry.reverse.inject([]) {|r, e| r.unshift(e) unless r.detect {|x|
> x.first == e.first}; r}

Couldn't resist throwing in another 1.9-esque version:

   arr.group_by(&:first).map(&:last).map(&:last)

:-) Of course mapping to [-1][-1] would work too (and probably more
efficiently).


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)