hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | type ExamWeightSource = { |
| 2 | kind?: string | null; |
| 3 | weight?: number | null; |
| 4 | }; |
| 5 | |
| 6 | type KindWeight = { |
| 7 | name: string; |
| 8 | weight: number; |
| 9 | }; |
| 10 | |
| 11 | export 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 | } |