From: Robert Klemme Date: 2009-04-03T01:23:21+09:00 Subject: Re: An array problem 2009/4/2 George George : > i have a 3 arrays(A,B,C) which are results of some analysis. I'd rather not make those constants (A,B,C) because they aren't as you stated. > Array A has all members such that array B and C are actually subsets of > A. The order of elements in array A is important. > > What i want is to list all members of A such that if an element in A is > a found in B or C produce a report such as > > element1 -b > element2 -b > element3 -c > element4 -b > .... > > where the order of elements in the report is as was in array A. > > > my rather silly implentation was > A.each do |element| >  if B.detect(element) >    puts "#{element}- b" >  end > end > > however i don't think this is the right way to do it since it does not > give me the designed result. Can someone help me spot the bug? You want #include? instead of #detect: a.each do |el| case when b.include? el puts "#{el} -b" when c.include? el puts "#{el} -c" end end Another hint: if A is really large (say 10_000 elements or more) it might be more efficient to convert B and C into Sets which have faster inclusion test. Or do it this way: occurrences = {} {b => "b", c => "c"}.each do |ar,label| ar.each {|el| occurrences[el] = label} end a.each do |el| label = occurrences[el] and puts "#{el} -#{label}" end Kind regards robert -- remember.guy do |as, often| as.you_can - without end