Use an Array as a set
Intersection of two arrays:
arr1 & arr2Union:
arr1 | arr2Remove all elements in arr2 from arr1, kinda like flags & ~FLAG_XXX in C:
arr2 - arr1In addition, by combining with assignment you can get
arr1 &= arr2
arr1 |= arr2
arr1 -= arr2works well.
Written by Shou Ya
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Ruby 
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
 
