Updated the counter of exercises

This commit is contained in:
Tiago Ribeiro
2023-10-15 22:54:40 +01:00
parent 18e12db7c5
commit f51dc450b9
7 changed files with 24 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
import {Module} from "@/interfaces";
import {Exercise} from "@/interfaces/exam";
export const MODULE_ARRAY: Module[] = ["reading", "listening", "writing", "speaking"];
@@ -16,3 +17,14 @@ export const sortByModule = (a: {module: Module}, b: {module: Module}) => {
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);
};