How to quickly know the difference between two arrays in Ruby (set)

Question: Question:

When you want to know something like a Venn diagram

p (array1 | array2).size
p (array1 & array2).size
p (array1 - (array1 & array2)).size
p (array2 - (array1 & array2)).size

But I just don't know how to do it smarter.
Is there any recommended method?

Also, is there a recommended method even when there are two or more arrays?

Answer: Answer:

For the time being, (a - (a & b)).size is redundant to find "the number of elements contained in set a but not in set b ".

(a - b).size

You can find it just by saying.

Scroll to Top