Ruby can do several set operations on arrays
# Intersection &
# Difference -
# Union |
# Intersection (&) creates a new array, merging the common elements of two arrays but removing uncommon elements and duplicates.
tue = [ "shop", "eat", "sleep" ]
wed = [ "shop", "eat", "read", "sleep" ]
tue & wed # => ["shop", "eat", "sleep"]
Related examples in the same category