First of all, I come from Obj-C and Python, so feel free to edit any faults in my JavaScript teminology.
I am looking for an efficient way of joining multiple dictionaries in JavaScript, where each key can exist in more than one dictionary and its values are arrays.
For example, I have:
{foo: [1,2], bar: [3,4]}
{foo: [5,6], baz: [7,8]}
And I want to join all the values of the same key, meaning I should return:
{foo: [1,2,5,6], bar: [3,4], baz: [7,8]}
I started doing something like the following pseudo code, but I feel like there should be a more efficient way of doing it.
// Pseudo code
return_value = {}
for (subset in full_array)
for (kv in subset)
data = return_value[kv] || []
data.push(subset[kv])
return_value[kv] = data