From: "Wolfgang Nádasi-Donner" Date: 2007-05-12T08:55:04+09:00 Subject: Re: how to remove dups from 2 lists? Wolfgang N�dasi-Donner schrieb: > Or is it something like this? > > ... > --- before --- > ["a", "b", "a", "a", "c", "a", "b", "c", "d", "e", "f", "e", "a"] > ["a", "b", "a", "c", "d", "c", "d", "c", "c", "g", "h", "g", "c"] > --- after --- > ["a", "a", "b", "e", "f", "e", "a"] > ["d", "c", "c", "g", "h", "g", "c"] If it is the wanted direction, the program is simple. class Array def remdups(b) a= self.dup b.each{|el|a.delete_at(a.index(el)) if a.include?(el)} a end end a = %w{a b a a c a b c d e f e a} b = %w{a b a c d c d c c g h g c} puts '--- before ---' p a p b puts '--- after ---' p a.remdups(b) p b.remdups(a) p [1,1,1,1].remdups([1,1,2]) p [1,1,2].remdups([1,1,1,1]) Output: --- before --- ["a", "b", "a", "a", "c", "a", "b", "c", "d", "e", "f", "e", "a"] ["a", "b", "a", "c", "d", "c", "d", "c", "c", "g", "h", "g", "c"] --- after --- ["a", "a", "b", "e", "f", "e", "a"] ["d", "c", "c", "g", "h", "g", "c"] [1, 1] [2] Wolfgang N�dasi-Donner