forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

exam-weight.ts22 lines, 580 bytesHistoryRawDownload
1type ExamWeightSource = {
2 kind?: string | null;
3 weight?: number | null;
4};
5
6type KindWeight = {
7 name: string;
8 weight: number;
9};
10
11export function examWeight(
12 source: ExamWeightSource,
13 kinds?: readonly KindWeight[] | null,
14): number | null {
15 const direct = source.weight ?? null;
16 if (typeof direct === "number" && Number.isFinite(direct)) return direct;
17 if (source.kind != null && kinds?.length) {
18 const match = kinds.find((item) => item.name === String(source.kind));
19 if (match && Number.isFinite(match.weight)) return match.weight;
20 }
21 return null;
22}