Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit abb8e7b

Browse files
GAD grader indentation - work for arbitrary (non-sequential number) tags
1 parent a1a07ac commit abb8e7b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

runestone/parsons/js/dagGrader.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,19 @@ export default class DAGGrader extends LineBasedGrader {
9595
checkCorrectIndentation(solutionLines, answerLines) {
9696
this.indentLeft = [];
9797
this.indentRight = [];
98+
99+
let indentationByTag = {};
100+
for (let i = 0; i < solutionLines.length; i++) {
101+
const line = solutionLines[i];
102+
indentationByTag[line.tag] = line.indent;
103+
}
104+
98105
let loopLimit = Math.min(solutionLines.length, answerLines.length);
99106
for (let i = 0; i < loopLimit; i++) {
100-
let solutionIndex = answerLines[i].tag;
101-
if (answerLines[i].viewIndent() < solutionLines[solutionIndex].indent) {
107+
let solutionIndent = indentationByTag[answerLines[i].tag];
108+
if (answerLines[i].viewIndent() < solutionIndent) {
102109
this.indentRight.push(answerLines[i]);
103-
} else if (answerLines[i].viewIndent() > solutionLines[solutionIndex].indent) {
110+
} else if (answerLines[i].viewIndent() > solutionIndent) {
104111
this.indentLeft.push(answerLines[i]);
105112
}
106113
}

0 commit comments

Comments
 (0)