I’m trying to write some code that removes all elements from 2 lists
that
are in both lists. However, I don’t want any duplicates from each list
deleted also (which is what the array “-” operator does). The code I
have
now doesn’t handle restarting the current iteration for both loops when
a
match is found and deleted in both loops. Here’s the code:
def RemoveDupsFromLists ( list1 , list2 )
list1.each_index do | i |
list2.each_index do | j |
if list1[i] == list2[j]
list1.delete_at ( i )
list2.delete_at ( j )
end
end
end
return [ list1 , list2 ]
end
What’s weird is that doing this is easy in C (my first language), but
difficult in Ruby. Everything else I’ve seen has been MUCH easier in
Ruby.
Mike S.