23 lines
520 B
TypeScript
23 lines
520 B
TypeScript
import { siteData } from '../data/site';
|
|
|
|
type Study = {
|
|
school: string;
|
|
study: string;
|
|
label: string;
|
|
start: Date;
|
|
end: Date | null;
|
|
};
|
|
|
|
|
|
function getStudy(studies: Study[]){
|
|
if (studies.length === 0) return null;
|
|
|
|
return studies.reduce((latest, study) => {
|
|
if (latest.end === null) return latest;
|
|
if (study.end === null) return study;
|
|
|
|
return study.start.getTime() > latest.start.getTime() ? study : latest;
|
|
});
|
|
}
|
|
|
|
export const study = getStudy(siteData.studies) |