gpt4 book ai didi

ruby - Rails 3 - 从数组 A 中删除属于数组 B 的项目

转载 作者:数据小太阳 更新时间:2023-10-29 06:28:47 25 4
gpt4 key购买 nike

我开始玩数组,但我被一些看起来非常简单的东西困住了...
我正在尝试从另一个数组中删除属于一个数组的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com