I stuck in a situation, I have an array of array structure how can I make it hash like below:-
Example:
[[378, 1], [144, 1], [144, 1], [144, 3], [144, 7], [144, 6], [144, 8], [144, 8], [809, 1], [809, 1], [809, 8]]
Convert to:
{378=>[1], 144=>[1,3,7,6,8], 809=>[1,8]}
means take the first element as key and make the second element in another array as value matched to key.
I tried below method but failed in one use case:
raw_hash = arr.group_by { |sub_arr| sub_arr[0] }
modified_hash = {}
raw_hash.each do |k, arr|
modified_hash[k] = [ arr.flatten.uniq - [ k ] ].flatten
end
failed use-case is if first element and second element both will same then it will make unique and subtract second value