I have an array of objects representing podcasts in a podcast app. Here is how the data looks:
[{ id: "uuid-1"
timeInSeconds: 1000
dateListened: "2021-01-01T15:57:17.000Z" }, // <---same day
{ id: "uuid-2"
timeInSeconds: 4900
dateListened: "2021-01-01T16:57:17.000Z" }, // <---same day
{ id: "uuid-3"
timeInSeconds: 3200
dateListened: "2021-09-01T16:57:17.000Z" },
{ id: "uuid-4"
timeInSeconds: 6000
dateListened: "2021-10-01T16:57:17.000Z" } ]
I am looking to create a function that can combine the activity times if the dateListened
falls on the same day. The desired output should resemble this:
[{ id: "uuid-new"
timeInSeconds: 5900 // <---- combined seconds listened on Jan 1
dateListened: "2021-01-01T15:57:17.000Z" },
{ id: "uuid-3"
timeInSeconds: 3200
dateListened: "2021-09-01T16:57:17.000Z" },
{ id: "uuid-4"
timeInSeconds: 6000
dateListened: "2021-10-01T16:57:17.000Z" } ]
I've tried using a .map() function with a nested .some() but I haven't been successful yet. If anyone has any hints or suggestions on what approach I should take next, I would appreciate it. Thank you!