开发者

Performing an outer join on two Ruby Arrays

开发者 https://www.devze.com 2023-02-02 02:42 出处:网络
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:

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 tha开发者_运维知识库t 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]
0

精彩评论

暂无评论...
验证码 换一张
取 消