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 matching element?
This is what I was trying but not quite getting the result.
x = [1, 2, 4]
y = [5, 2, 4]
x.each do |num|
puts " The number #{num} is in the array" if x.include?(y.each)
end #=> [1, 2, 4]
You can use the set intersection method
&for that: