From: Chuck Remes Date: 2009-07-20T11:13:47+09:00 Subject: Re: removing array duplicates where a subset is unique On Jul 19, 2009, at 5:07 PM, Siep Korteling wrote: > David A. Black wrote: >> Hi -- >> >> On Mon, 20 Jul 2009, 7stud -- wrote: >> >>>> >>> [2, 2, 3, 40] >>> h[key] = suba >>> end >>> >>> end >>> >>> p h.values >>> >>> --output:-- >>> [[2, 2, 3, 40], [1, 2, 3, 10]] >> >> I'm not sure what that buys you, though. The ||= idiom should work >> fine, unless you need to do something extra during the if statement. >> >> >> David > > Facets has enumerable#uniq_by implemented like this: > > def uniq_by #:yield: > h = {}; inject([]) {|a,x| h[yield(x)] ||= a << x} > end Ooh, I like this one too. I'll try it out and see what kind of performance I get. I understand that #inject performance is weak in MRI 1.8, but I primarily use JRuby where it doesn't share the same performance issues as the C version. cr