Last active
December 10, 2015 14:08
-
-
Save aeg/4445509 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', 'd'] | |
list1.remove(2) | |
assert list1 == ['a', 'b', 'd'] | |
// Case #2 | |
// リストの任意の要素を値を指定して削除する | |
def list2 = ['a', 'b', 'c', 'b'] | |
// リストで先頭から発見された最初の要素しか削除されない | |
list2.remove('b') | |
assert list2 == ['a', 'c', 'b'] | |
// 2回呼び出すことにより削除される | |
result = list2.remove('b') | |
assert list2 == ['a', 'c'] | |
// 削除ができた場合には result = true | |
assert result == true | |
assert list2 == ['a', 'c'] | |
result = list2.remove('b') | |
// 削除ができなかった場合には result == false | |
assert result == false | |
assert list2 == ['a', 'c'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment