演示(我期望结果[3]
):
[1,2] - [1,2,3] => [] # Hmm
[1,2,3] - [1,2] => [3] # I see
a = [1,2].to_set => #<Set: {1, 2}>
b = [1,2,3].to_set => #<Set: {1, 2, 3}>
a - b => #<Set: {}> WTF!
和:
[1,2,9] - [1,2,3] => [9] # Hmm. Would like [[9],[3]]
无论输入的顺序如何,如何执行真正的设置差异?
附言。顺便说一句,我需要为两个 2000 元素数组执行此操作。通常,数组#1 的元素比数组#2 少,但这并不能保证。