Pretty easy stuff today, but this is not something you may need to do often so maybe you don’t know how to do it.
Say I have these 2 arrays :
-
colors1 = [:blue, :red, :green, :orange, :purple]
-
colors2 = [:yellow, :cyan, :green, :blue, :purple]
Now what if I want a new array that contains only the elements present in both arrays?
-
beautiful_colors = colors1 & colors2
-
#beautiful_colors contains [:blue, :green, :purple]
Have a nice weekend!
Bookmark this post :
These icons link to social bookmarking sites where readers can share and discover new web pages.
Rate this post :

Loading ...