From: rpmohn@... (Ross Mohn) Date: 2000-12-03T12:40:05+09:00 Subject: [ruby-talk:6759] Re: Array Intersect (&) question matju@cam.org (Mathieu Bouchard) wrote in : >I think you can preserve order and use hashes. > >class Array > def &(other) > t = {} > r = [] > other.each {|x| t[x]=1 } > uniq.each {|x| r< r > end > def |(other) > t = {} > r = [] > (self+other).each {|x| r< r > end > def uniq; self|[] end >end a1 = %w# a b c c c # a2 = %w# b c # a1 & a2 -> ["b", "c", "c", "c"] a2 & a1 -> ["b", "c"] I don't think that's okay:) -RPM -- Ross Mohn rpmohn@panix.com