From: Mike Steiner Date: 2007-05-12T00:35:28+09:00 Subject: Re: how to remove dups from 2 lists? ------=_Part_82297_17105422.1178897727281 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Wow - this question generated lots of replies! I'm still reading through all of them. I have another idea, but not sure if this will work: def RemoveDupsFromLists ( list1 , list2 ) list1.each_item do | i | list2.each_item do | j | if !(list2[j].nil?) and list1[i] == list2[j] list1[i] = nil list2[j] = nil end end end list1.compact! list2.compact! return [ list1 , list2 ] end On 5/11/07, Lloyd Linklater wrote: > > Harry Kakueki wrote: > > > What happens here? :) > > All 5's are deleted. > > If you are asking about my example, there were no 5s in it to begin > with. As was observed earlier, I think that better examples would have > resulted in better code. I was mostly interested in finding a rubyish > way to make it happen with great simplicity. If there is something > slightly different needed, perhaps a tweak or two to the arrays before > applying the differences could handle it. > > Anyway, this is my first attempt at writing code to solve a question in > here. I am happy that I was able to come up with something that worked > and post it. :) > > yay ruby! > > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_82297_17105422.1178897727281--