// differenceInDays и format импортированы из date-fns
function invertArray(array: DepartureDate[] = []): DepartureDate[]
{
if (!array.length) {
return [];
}
const first = array.slice().shift();
const last = array.slice().pop();
const days = differenceInDays(parse(last.date), parse(first.date));
const dates = [{date: first.date, minTicketPrice: 0}];
for (let i = 1; i < days; i++) {
const date = format(addDays(parse(first.date), i), 'YYYY-MM-DD');
dates.push({date, minTicketPrice: 0});
}
return (uniqBy([...array, ...dates], 'date') as DepartureDate[]).filter(date => !date.minTicketPrice);
}