I am trying to create a intersection statement using a foreach loop
for example
cand[0][1,2,5]
cand[1][2,5,6]
@result = cand[0] & cand[1]
with a for each
intersec = Array.new
cand.each do |c|
intersec = intersec & c
end
@result = intersec
I get an empty array
Thanks
Alex
I think you are trying to do something like
cand[0] & cand[1] & cand[2]
you can do this using
intersection = cand.reduce(:&)
Let me know if it works