UNPKG

@swapper-finance/sdk

Version:
20 lines (17 loc) 593 B
import { HistoryEntry } from "@src/interfaces"; export const groupHistoryByDate = ( history: HistoryEntry[], ): Record<string, HistoryEntry[]> => { return history.reduce<Record<string, HistoryEntry[]>>((acc, entry) => { const date = new Date(entry.date); const day = date.getDate().toString().padStart(2, "0"); const month = (date.getMonth() + 1).toString().padStart(2, "0"); const year = date.getFullYear(); const dateKey = `${day}/${month}/${year}`; if (!acc[dateKey]) { acc[dateKey] = []; } acc[dateKey].push(entry); return acc; }, {}); };