Performing an outer join on two Ruby Arrays

前提是你 提交于 2019-12-11 12:51:05

问题


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.


回答1:


old = [1, 2, 3, 4]
new = [2, 3, 4, 5, 6]
p new - old #=[5, 6]


来源:https://stackoverflow.com/questions/4592918/performing-an-outer-join-on-two-ruby-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!