Skip to content

Commit

Permalink
Make the repetition code compliant with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aaruni96 committed Mar 14, 2022
1 parent 4af556a commit 3bfd44d
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/environments/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,12 +783,23 @@ defineEnvironment({
symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body;
let myColAlign = [];
if (colalign[0].text === "*") {
const numStart = colalign[1].loc.start + 1;
const numEnd = colalign[1].loc.end - 1;
const iRepeat = colalign[0].loc.lexer.input.slice(numStart, numEnd);
for (let i = 0; i < iRepeat; i++) {
for (let j = 0; j < colalign[2].body.length ; j++) {
myColAlign.push(colalign[2].body[j]);
const repeatCol = assertNodeType(colalign[1], "ordgroup");
let repeatString = "";
for (let i = 0; i < repeatCol.body.length ; i++) {
const iRepeat = assertNodeType(repeatCol.body[i], "textord");
repeatString += iRepeat.text ;
}
const nRepeat = parseInt(repeatString);
if (isNaN(nRepeat)) {
throw new ParseError("Repeat specification not a number: "
+ repeatString, repeatCol);
}
const ca = assertNodeType(colalign[2], "ordgroup");
const caLength = ca.body.length;
for (let i = 0; i < nRepeat; i++) {
for (let j = 0; j < caLength ; j++) {
const jca = assertNodeType(ca.body[j], "mathord");
myColAlign.push(jca);
}
}
} else {
Expand Down

0 comments on commit 3bfd44d

Please sign in to comment.