getEachLatestDate
与えられた日時のリストから、各日付で最新のものだけを一つづつ取り出したリストを作る
code:mod.ts
import { isSameDay, getYear, getMonth, getDate } from "../date-fns/mod.ts";
export const getEachLatestDate = (dates: Date[]): Date[] => {
const map = new Map<${number}-${number}-${number}, Date>();
for (const date of dates) {
const key = ${getYear(date)}-${getMonth(date)}-${getDate(date)} as const;
const sameDate = map.get(key);
if (sameDate && sameDate.getTime() > date.getTime()) continue;
map.set(key, date);
}
};