From: Adam Shelly Date: 2006-02-05T13:53:18+09:00 Subject: Re: Quiz #65, Principle of Great Surprise, and Array.delete sledgehammer On 2/4/06, Dave Howell wrote: > > ... . The "-" operator also was > massively destructive, removing all duplicates when used. I ran into that problem too when I was coding the quiz. Does anyone else find it strange that a + b - b != a if a contains duplicates of any element in b? To finish the quiz, I added this method: class Array def subtract arr return clear if arr==self arr.each{|e| if (n=index(e)) then delete_at(n); end } self end end a = [1,2,3,3,3,4,5,5,6] => [1, 2, 3, 3, 3, 4, 5, 5, 6] b = [3,4,5] => [3, 4, 5] a.subtract b => [1, 2, 3, 3, 5, 6] a => [1, 2, 3, 3, 5, 6] -Adam