Created
June 1, 2010 20:12
-
-
Save zhengjia/421413 to your computer and use it in GitHub Desktop.
array include
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#You can just use a set difference (aka minus) to see if one array includes all elements of another | |
not_included = [1,2,3] - (1..9).to_a | |
not_included # => [] | |
not_included = [1,2,3,'A'] - (1..9).to_a | |
not_included # => ["A"] | |
#Use intersection to test if any of the one are in the other: | |
shared = [1,2,3,'A'] & (1..9).to_a | |
shared # => [1, 2, 3] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment