-
-
Save mistyrinth/f1f98d34aaf376ebe8b55e55c8f16963 to your computer and use it in GitHub Desktop.
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
array = ["晴れ", "曇り", nil, "雨", "晴れ", "雪"] | |
puts "元の配列は #{array} です" | |
# 重複要素の削除 | |
newarray1 = array.uniq | |
puts "重複を削除した配列は #{newarray1} です" | |
# nilの削除 | |
newarray2 = newarray1.compact | |
puts "更にnilを削除した配列は #{newarray2} です" | |
# 指定した値の削除 | |
newarray2.delete("雪") | |
puts "指定した値を削除すると #{newarray2} です" | |
# 指定したインデックスの要素の削除 | |
newarray2.delete_at(0) | |
puts "指定したインデックスを削除すると #{newarray2} です" | |
# ブロック内の処理がtrueの要素の削除 | |
ary = [1, 2, 3, 4, 5, 6, 7, 8] | |
puts "元の配列は #{ary} です" | |
ary.delete_if{|x| | |
x % 2 == 0 | |
} | |
puts "削除後の配列は #{ary} です" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment