32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import {Module} from "@/interfaces";
|
|
import {Exercise} from "@/interfaces/exam";
|
|
|
|
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking", "level"];
|
|
|
|
export const moduleLabels: {[key in Module]: string} = {
|
|
listening: "Listening",
|
|
reading: "Reading",
|
|
speaking: "Speaking",
|
|
writing: "Writing",
|
|
level: "Level",
|
|
};
|
|
|
|
export const sortByModule = (a: {module: Module; [key: string]: any}, b: {module: Module; [key: string]: any}) => {
|
|
return MODULE_ARRAY.findIndex((x) => a.module === x) - MODULE_ARRAY.findIndex((x) => b.module === x);
|
|
};
|
|
|
|
export const sortByModuleName = (a: string, b: string) => {
|
|
return MODULE_ARRAY.findIndex((x) => a === x) - MODULE_ARRAY.findIndex((x) => b === x);
|
|
};
|
|
|
|
export const countExercises = (exercises: Exercise[]) => {
|
|
const lengthMap = exercises.map((e) => {
|
|
if (e.type === "multipleChoice") return e.questions.length;
|
|
if (e.type === "interactiveSpeaking") return e.prompts.length;
|
|
|
|
return 1;
|
|
});
|
|
|
|
return lengthMap.reduce((accumulator, current) => accumulator + current, 0);
|
|
};
|