我开始使用数组,但是我坚持使用看起来但非常简单的东西...
我正在尝试从另一个数组中删除属于一个数组的x个元素。
我已经看过了,但是....阻止了:
Deleting items from an array requires multiple passes to remove them all
a = ["1","2","3","4","5","6"]
b = ["1","3"]
c = a.reject { |i| i =~ /b/ }
好吧,我在这里很多,谢谢!
最佳答案
a = ["1","2","3","4","5","6"]
b = ["1","3"]
c = a - b
和...一样
c = a.reject{ |e| b.include? e }
关于ruby - Rails 3-从阵列A移除属于阵列B的项目,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5648198/