Array operations in Ruby 🗄

Easy way to get the intersection, union, and subset of arrays in Ruby 👇🏼

Code snippet 📌

x = [1, 1, 2, 4]
y = [1, 2, 2, 2]

# intersection
x & y            # => [1, 2]

# union
x | y            # => [1, 2, 4]

# difference
x - y            # => [4]