From: Tod Beardsley Date: 2008-09-17T00:08:56+09:00 Subject: Re: array question Case 1 and 2, maybe the desired result? irb(main):088:0> def there_can_be_only_one(arr) irb(main):089:1> arr.sort!.collect {|x| (arr[arr.index(x)] != arr[arr.index(x)+1] ? x:nil)}.compact irb(main):090:1> end => nil irb(main):091:0> there_can_be_only_one([1,2,3] + [1,4,7]) => [2, 3, 4, 7] irb(main):092:0> there_can_be_only_one([1,2,2,3] + [1,4,7,7]) => [3, 4] irb(main):093:0> ...assumes the elements to be compared are all the same type (Fixnums can't sort with Strings, eg) On Tue, Sep 16, 2008 at 9:29 AM, Nathan Powell wrote: > On Tue, Sep 16, 2008 at 11:25:00PM +0900, Amos King wrote: >> Forgot to ask what he was looking for. > > In the original email: > > > For example, array1=[1,2,3],array2=[1,4,7] > the return array is [2,3,4,7] > > > It's not entirely clear as one could arrive at that final array a couple > ways. > > -- > nathan > nathan_at_nathanpowell_dot_org > > At this point, anyone proposing to run Windows on servers should be prepared > to explain what they know about servers that Google, Yahoo, and Amazon don't. > ~ Paul Graham > ------------------------------------ > > -- todb@planb-security.net | ICQ: 335082155 | Note: Due to Google's privacy policy and the United States' policy on electronic surveillance , please do not IM/e-mail me anything you wish to remain secret.