From: rpmohn@... (Ross Mohn) Date: 2000-12-03T12:40:01+09:00 Subject: [ruby-talk:6758] Re: Array Intersect (&) question rpmohn@panix.com (Ross Mohn) wrote in <8FFEE72C5rpmohnpanixcom@166.84.0.240>: >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 Oops, nevermind. I didn't see the "uniq" first time through! -RPM -- Ross Mohn rpmohn@panix.com