32 lines
1002 B
TypeScript
32 lines
1002 B
TypeScript
import {Module} from "@/interfaces";
|
|
import {Exercise} from "@/interfaces/exam";
|
|
|
|
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking"];
|
|
|
|
export const moduleLabels: {[key in Module]: string} = {
|
|
listening: "Listening",
|
|
reading: "Reading",
|
|
speaking: "Speaking",
|
|
writing: "Writing",
|
|
level: "Level",
|
|
};
|
|
|
|
export const sortByModule = (a: {module: Module}, b: {module: Module}) => {
|
|
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);
|
|
};
|