I have two arrays that represent records from a User table.
@server = [{ id: 1, name: "john" }, { id: 2, name: "Sarah" }, { id: 3, name: "George" }]
@client = [{ id: 1, name: "john" }, { id: 2, name: "Sarah" }]
I want to run a function that checks one array against the other and deletes George's record because they no longer exist in @client
At the moment I have this rather long looking method, which works but definitely doesn't look optimal.
@server.each do |item|
if @client.select{ |obj| obj[:id] == item.id }.length < 1
User.find(item.id).delete
end
end
What is the optimal method for this problem?