mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-01-11 03:02:31 -05:00
25 lines
631 B
TypeScript
25 lines
631 B
TypeScript
export type ProgressTimestamp = number | { timestamp: number } | null;
|
|
|
|
export const getCalendar = (
|
|
progressTimestamps: ProgressTimestamp[] | null
|
|
): Record<string, 1> => {
|
|
const calendar: Record<string, 1> = {};
|
|
|
|
progressTimestamps?.forEach(progress => {
|
|
if (progress === null) return;
|
|
if (typeof progress === 'number') {
|
|
calendar[Math.floor(progress / 1000)] = 1;
|
|
} else {
|
|
calendar[Math.floor(progress.timestamp / 1000)] = 1;
|
|
}
|
|
});
|
|
|
|
return calendar;
|
|
};
|
|
|
|
export const getPoints = (
|
|
progressTimestamps: ProgressTimestamp[] | null
|
|
): number => {
|
|
return progressTimestamps?.length ?? 1;
|
|
};
|