reject和reject!
reject返回不满足代码块的元素数组
reject!删除数组中满足代码块的元素
a=[1,2,3,5]
a.reject! {|x| x<4}
p a #[5] b = [1,2,3,4,5]
c = b.reject {|x| x>4}
p c
p b
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
2022-10-10 13:40:58
reject和reject!
reject返回不满足代码块的元素数组
reject!删除数组中满足代码块的元素
a=[1,2,3,5]
a.reject! {|x| x<4}
p a #[5] b = [1,2,3,4,5]
c = b.reject {|x| x>4}
p c
p b
[1, 2, 3, 4]
[1, 2, 3, 4, 5]