执行两个红宝石阵列外连接 [英] Performing an outer join on two Ruby Arrays
本文介绍了执行两个红宝石阵列外连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我们说我有在Ruby中两个数组包含用户ID。
这是老用户:
== ==老
1
2
3
4
这些都是新的:
== ==新
2
3
4
五
6
我要的找到新的用户的ID,所以在这种情况下,5和6。我想我要的是一个左外连接NEW和OLD的,但我不知道该怎么做了简单的数组。
我是比较新的红宝石,因此有可能是一个简单而有效的解决方案,对于这一点,而不是迭代的一切。
解决方案
老= [1,2,3,4]
新= [2,3,4,5,6]
p新 - 老#= [5,6]
Let's say I have two Arrays in Ruby, containing user IDs.
These are the old users:
== old ==
1
2
3
4
And these are the new:
== new ==
2
3
4
5
6
I want to find out the IDs of new users, so in that case, 5 and 6. I guess what I want is a left outer join of NEW and OLD, but I don't know how to do that with simple arrays.
I'm relatively new to Ruby, so there might be a simple and effective solution for this, rather than iterating over everything.
解决方案
old = [1, 2, 3, 4]
new = [2, 3, 4, 5, 6]
p new - old #=[5, 6]
这篇关于执行两个红宝石阵列外连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文