I have an array of objects like:
const dates = [
{date: "Jul 06 2018", count: 10},
{date: "Jul 08 2018", count: 1},
{date: "Jul 10 2018", count: 120},
];
I am working with the eachDay and format functions of date-fns to generate and "backfill" all dates that exist between the first and last dates for the given array.
eachDay(
dates[0].date,
dates.slice(-1)[0].date,
)
.map(d => ({
x: d.dateCollected,
y: dates
.filter(e => d.dateCollected === format(e, 'MMM DD YYYY')),
}));
That codes returns all the dates, but I cannot get the count value from the original array into the "backfilled" array.
The expected outcome:
const result = = [
{x: "Jul 06 2018", y: 10},
{x: "Jul 07 2018", y: 0},
{x: "Jul 08 2018", y: 1},
{x: "Jul 09 2018", y: 0},
{x: "Jul 10 2018", y: 120},
];
xandyproperties in your code when the expected outcome should not have those properties? What is the idea?xandykeys.