Ruby Array Set Intersection
Ruby's Array class has a method &
which returns a new array containing elements common to two arrays, excluding duplicates.
I used this on a project today to compare a random number (17) to a set of numbers with special meaning to the program.
The order is preserved from the original array:
h/t Chris Erin
Tweet