Updated the counter of exercises
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user