找出考虑重复的两个数组之间的差异

时间:2017-12-04 01:21:57

标签: arrays ruby

我试图比较两个哈希数组,并删除旧记录。 stale_records是来自old_records的{​​{1}}中不存在的记录new_records。数组中的项目可以重复。

old_records = [{a: 1}, {b: 2}]
new_records = [{a: 1}]
stale_records = #=> [{:b=>2}]

old_records = [{a: 1}, {a: 1}]
new_records = [{a: 1}]
stale_records #=> [{a: 1}]

我想知道几百万条记录是否有效。

我试过了:

old_records = [{a: 1}, {b: 2}]
new_records = [{a: 1}]
stale_records = old_records - new_records #=> [{:b=>2}]

old_records = [{a: 1}, {a: 1}]
new_records = [{a: 1}]
stale_records = old_records - new_records #=> []

在项目重复时没有给出正确的结果。

0 个答案:

没有答案