I'm trying to merge 2 objects together, however there is a possibility for X number of duplicated items. As an example, I already have historyExisting, and I want to add historyNew to it. You can see there are duplicates
Sample Data
var historyExisting = {
'1505845390000': 295426,
'1505757979000': 4115911,
'1505677767000': 4033384,
'1505675472000': 4033384,
'1505591090000': 3943956
}
var historyNew = {
'1505675472000': 4033384,
'1505591090000': 3943956,
'1505502071000': 3848963,
'1505499910000': 3848963,
'1505499894000': 3848963
}
Desired Outcome
var history = {
'1505845390000': 295426,
'1505757979000': 4115911,
'1505677767000': 4033384,
'1505675472000': 4033384,
'1505591090000': 3943956,
'1505502071000': 3848963,
'1505499910000': 3848963,
'1505499894000': 3848963
}
As you can see, the outcome is still kept in timestamp order, but any duplication has been removed. I've been trying to get the last item key/value in historyExisting, find that in historyNew, remove any items before that and then merge them but it seems extremely clunky.
This is server side in Node, so not browser dependent.
Any suggestions?