There are two arrays of hashes
actual = [{id: 1, text: "A", type: "X", state: "enabled"}, {id: 2, text: "B", type: "X", state: "enabled"}]
expected = [{text: "A", type: "X", state: "enabled"}]
I need to get the :id of all Hash not included in "expected". The comparison has to be done using three keys (text, type, state). In this case
results = [{id: 2}]
At the moment I am using this but it's very long and not performing for a big array. Is there a better way?
actuals = actuals.map{|a| a.slice(:text, :type, :state)}
expected = expected.map{|a| a.slice(:text, :type, :state)}
not_expected = actuals - expected
results = actuals.select{|actual|
not_expected.find{|n|
n[:text] == actual[:text] &&
n[:type] == actual[:type] &&
n[:state] == actual[:state]
}.present?
}