I don't mind using a library to solve this problem, especially if it simplifies the code.
I've got some data like this:
[{source: 'b', foo: 'bar'},
{source:'d', foo: 'baz'}]
And I've got another array like this:
['b', 'c', 'e']
I'd like to process these two arrays and get this as output:
[{source: 'b', foo: 'bar'},
{source: 'c', foo: 'someDefaultValue'},
{source:'d', foo: 'baz'},
{source: 'e', foo: 'someDefaultValue'}]
To elaborate, if data is in the first array, it should remain in the result. If data is in the second array, it should appear in the result with default values. I want the result to be sorted by source.
In SQL terms, I'd refer to this as a "Full Outer Join on the source column." I'm finding it difficult to write code in JavaScript that works this way. How would I get the result given the two inputs?