Last active
December 10, 2015 10:18
-
-
Save aeg/4419954 to your computer and use it in GitHub Desktop.
リストの和と積をとる
This file contains hidden or 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
// Case #1 | |
// リストの集合演算的な和をとる | |
def list1 = ['a' ,'b', 'c'] | |
def list2 = ['b', 'c', 'd', 'e'] | |
assert (list1 + list2).unique() == ['a', 'b', 'c', 'd', 'e'] | |
// Case #2 | |
// リストの集合演算的な積をとる(リストの共通部分をとる) | |
assert list1.intersect(list2) == ['b', 'c'] | |
// Case #3 | |
// リストの集合演算的な差をとる | |
// list2 にある要素を list1 から消したものが得られる | |
assert list1 - list2 == ['a'] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment