From: Kevin Compton Date: 2007-05-12T01:06:17+09:00 Subject: Re: how to remove dups from 2 lists? ------=_Part_172061_12852983.1178899576069 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Looks good to me! each_item should read each_index and (perhaps) remove nil check and we're off. On 5/11/07, Mike Steiner wrote: > > 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_172061_12852983.1178899576069--