I am faced with the task of merging two arrays of objects into a single array based on their timestamps. One array contains exact second timestamps, while the other consists of hourly ranges. My goal is to incorporate the 'humidity' values from the array with exact timestamps into the one with hourly ranges, aligning them chronologically. How can I achieve this in typescript? Both arrays/objects are already sorted by time.
Here's an example:
[{id: 1, timestampUtc: "2019-02-22T08:24:00Z", humidity: 74},
{id: 2, timestampUtc: "2019-02-24T06:20:00Z", humidity: 39},
{id: 3, timestampUtc: "2019-02-26T020:03:00Z", humidity: 35}]
and
[{id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03},
{id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3},
{id: 6, starttimestampUtc: "2019-02-26T020:00:00Z",endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12}]
The desired output should be:
[{id: 4, starttimestampUtc: "2019-02-22T08:00:00Z", endtimestampUtc: "2019-02-22T09:00:00Z", precipitation: .03, humidity: 74},
{id: 5, starttimestampUtc: "2019-02-24T06:00:00Z", endtimestampUtc: "2019-02-24T07:00:00Z", precipitation: .3, humidity: 39},
{id: 6, starttimestampUtc: "2019-02-26T020:00:00Z", endtimestampUtc: "2019-02-26T021:00:00Z", precipitation: .12, , humidity: 35}]