I have an array of hashes:
a = [{'id'=> '1', 'subject'=> 'this is subject 1', 'orig_id'=> 123, 'parent_id'=> 123},
{'id'=> '2', 'subject'=> 'this is subject 2', 'orig_id'=> 456, 'parent_id'=> 123},
{'id'=> '3', 'subject'=> 'this is subject 3', 'orig_id'=> 789, 'parent_id'=> 980}]
I want to filter it based on the condition that if the parent_id of one object is equal to the orig_id or the parent_id of the other object then keep the first hash and remove the other.
From the above scenario, the second hash will be removed and the output would be:
a = [{'id'=> '1', 'subject'=> 'this is subject 1', 'orig_id'=> 123, 'parent_id'=> 123},
{'id'=> '3', 'subject'=> 'this is subject 3', 'orig_id'=> 789, 'parent_id'=> 980}]
a = [{‘parent_id’=>1, ‘user_id’=>2}, {‘parent_id’=>2, ‘user_id’=>3}, {‘parent_id’=>3, ‘user_id’=>1}]. What is the desired return value, and why?