Files
freeCodeCamp/api/src/utils/progress.ts
Oliver Eyton-Williams 6e787d3336 feat(api): add /user/get-session-user (#50557)
Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
2023-07-11 16:28:56 +00:00

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;
};