Предполагая, что вы хотите вернуть только количество (не группировки):
const dates = [
new Date('July 12, 2020 00:15:30'),
new Date('July 12, 2020 03:15:30'),
new Date('July 07, 2020 02:15:30'),
new Date('July 02, 2020 01:15:30'),
new Date('July 08, 2020 12:15:30'),
new Date('July 07, 2020 00:15:30'),
new Date('July 07, 2020 03:15:30'),
new Date('July 01, 2020 00:15:30')
]
const today = new Date();
function daysDifference(date1, date2) {
var difference = (date2.getTime() - date1.getTime()) / 1000;
difference /= (60 * 60 * 24);
return Math.abs(Math.round(difference))
}
function countDifferences(arr, constant) {
return arr.reduce((output, date) => {
let key = daysDifference(date, constant);
output[key] ? output[key] += 1 : output[key] = 1;
return output
}, {})
}
console.log(countDifferences(dates,today))