If I want to compare two arrays and create an interpolated output string if an array variable from array y
exists in x
how can I get an output for each
OK, so the &
operator appears to be the only thing you need to do to get this answer.
But before I knew that I wrote a quick monkey patch to the array class to do this:
class Array
def self.shared(a1, a2)
utf = a1 - a2 #utf stands for 'unique to first', i.e. unique to a1 set (not in a2)
a1 - utf
end
end
The &
operator is the correct answer here though. More elegant.