UNPKG

analytica-frontend-lib

Version:

Repositório público dos componentes utilizados nas plataformas da Analytica Ensino

78 lines (77 loc) 2.6 kB
// src/components/Quiz/Quiz.utils.ts var formatExamInfo = (examBoard, examYear) => { if (examBoard && examYear) { return `(${examBoard} - ${examYear})`; } if (examBoard) { return `(${examBoard})`; } if (examYear) { return `(${examYear})`; } return ""; }; var shuffleWithSeed = (array, seed) => { const shuffled = [...array]; let hash = 0; for (let i = 0; i < seed.length; i++) { const char = seed.codePointAt(i) ?? 0; hash = (hash << 5) - hash + char; hash = hash & hash; } const seededRandom = (max) => { hash = hash * 1103515245 + 12345 & 2147483647; return hash % max; }; for (let i = shuffled.length - 1; i > 0; i--) { const j = seededRandom(i + 1); [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } return shuffled; }; var prependLetterToHtml = (letter, html) => { if (html.trim().startsWith("<p>")) { return html.replace(/^(\s*<p>)/, `$1${letter}) `); } return `${letter}) ${html}`; }; var getTrueOrFalseOptionState = (optionId, variant, currentQuestionResult, localAnswers) => { const correctAnswerOption = currentQuestionResult?.options?.find( (op) => op.id === optionId ); const isStatementTrue = variant === "result" /* RESULT */ ? correctAnswerOption?.isCorrect ?? false : false; const studentSelection = variant === "result" /* RESULT */ ? currentQuestionResult?.selectedOptions?.find( (op) => op.optionId === optionId ) : void 0; const hasAnswered = variant === "result" /* RESULT */ ? studentSelection !== void 0 : !!localAnswers[optionId]; const studentMarkedTrue = variant === "result" /* RESULT */ ? studentSelection?.isCorrect ?? false : localAnswers[optionId] === "V" /* VERDADEIRO */; const getStudentAnswerDisplay = () => { if (variant !== "result" /* RESULT */) { return localAnswers[optionId] || "-"; } if (!hasAnswered) { return "-"; } return studentMarkedTrue ? "V" /* VERDADEIRO */ : "F" /* FALSO */; }; const studentAnswer = getStudentAnswerDisplay(); const correctAnswer = isStatementTrue ? "V" /* VERDADEIRO */ : "F" /* FALSO */; const isStudentCorrect = hasAnswered && studentMarkedTrue === isStatementTrue; const variantCorrect = isStudentCorrect ? "correct" /* CORRECT */ : "incorrect" /* INCORRECT */; return { isStatementTrue, hasAnswered, studentMarkedTrue, studentAnswer, correctAnswer, isStudentCorrect, variantCorrect }; }; export { formatExamInfo, shuffleWithSeed, prependLetterToHtml, getTrueOrFalseOptionState }; //# sourceMappingURL=chunk-DDZDNGBU.mjs.map