I am trying to merge two arrays into one. First one has default configuration and the second one has actual one. I found very similar problem here, but in my specific case it does not work.
Default configuration:
[
{ configurationOption: 'X provisioning', platform: 'X', value: true },
{ configurationOption: 'Y provisioning', platform: 'Y', value: true },
{ configurationOption: 'Z provisioning', platform: 'Z', value: true }
]
Actual configuration:
[
{ platform: 'X', value: false },
{ platform: 'Y', value: true }
]
Expected result:
[
{ configurationOption: 'X provisioning', platform: 'X', value: false },
{ configurationOption: 'Y provisioning', platform: 'Y', value: true },
{ configurationOption: 'Z provisioning', platform: 'Z', value: true }
]
So basically what it needs to do is update 'value' property of default configuration, based on actual one, tricky part is that some of configurationItem does not exist in actual configuration and actual configuration is missing 'configurationOption' property.
var config = _.unionBy(actual, defaultConf, 'platform');
This line is the closest one I could get, but is missing 'configurationOption' property.
Here is CodePen so you can play around with it: https://codepen.io/anon/pen/oBwLMb?editors=0012