Or somewhat faster, particularly for long arrays:
class Array
def rem_dups(b)
a = dup
b.each { | e | i = a.index(e); a.delete_at(i) if i}
a
end
end
Which avoids scanning the array twice for each element.
···
On 5/11/07, Wolfgang Nádasi-Donner <wonado@donnerweb.de> wrote:
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
--
Rick DeNatale
My blog on Ruby
http://talklikeaduck.denhaven2.com/