From: Tobias Reif Date: 2002-02-11T19:17:02+09:00 Subject: Re: array diff Hi, nobu.nokada@softhome.net wrote: > class Array > def diff(a) > ary = dup > a.each {|i| ary.delete_at(i) if i = ary.index(i)} > ary > end > end > > p [1,2,3].diff [3,1] # => [2] > p [1,2,3,3].diff [3,3,1] # => [2] > p [1,1,1].diff [1,1] # => [1] But [1,1].nobus_diff [1,1,1] -> [] So here#s what I had def diff other if self.length >= other.length longer = self.dup shorter = other.dup elsif self.length <= other.length longer = other.dup shorter = self.dup end shorter.each do |el| if longer.index(el) longer.delete_at longer.index(el) end end longer end Tobi -- * peace&love. * http://www.pinkjuice.com/