I have been using the reduce method along with the dayOfYear function to calculate the average date from an array of dates.
While my current solution functions well for dates within the same year, it unfortunately overlooks the discrepancy in years between the dates.
return moment().dayOfYear(Math.round(items.reduce((a, b) => a + moment(b).dayOfYear(), 0) / items.length)).format('YYYY-MM-DD');
Can anyone provide some guidance on how I can modify the above code to account for the difference in years between the dates? Any assistance would be greatly appreciated.