Commit cef1979b authored by nanahira's avatar nanahira

use common methods

parent 13ef911c
......@@ -38,9 +38,20 @@ async function loadConstants() {
}
}
function joinWithAnd(clauses: string[]) {
return `and (1 ${clauses.join(" ")})`;
}
function joinWithOr(clauses: string[]) {
const wrappedClauses = clauses.map(c => `(1 ${c})`)
return `and (${wrappedClauses.join(" or ")})`;
}
function wrapWithNot(clause: string) {
return `and not (1 ${clause})`;
}
function replaceClause(clause: string | any, statement: boolean) {
if (typeof (clause) !== "string") {
return (statement === (clause === 0)) ? "0" : "1";
return (statement === (clause === 0)) ? "and 0" : "and 1";
}
let newClause = clause;
for (let constantKey of Array.from(constantDict.keys())) {
......@@ -59,7 +70,7 @@ function parseWhereClause(whereClause: (string | any)[]) {
return "";
}
const newClauses = whereClause.map(w => replaceClause(w, true));
return newClauses.join(' ');
return joinWithAnd(newClauses);
}
function getCombination(arr: number[], count: number): number[][] {
......@@ -105,11 +116,10 @@ function parseMayIncorrectStatement(mayIncorrectStatement: MayIncorrectStatement
const correctSequences = generateBoolSequence(mayIncorrectStatement.where.length, i);
for (let correctSequence of correctSequences) {
const clauses = mayIncorrectStatement.where.map((clause, index) => replaceClause(clause, correctSequence[index]));
const combinedClause = `(1 ${clauses.join(' ')})`;
outerClauses.push(combinedClause);
outerClauses.push(joinWithAnd(clauses));
}
}
return `and (${outerClauses.join(' or ')})`;
return joinWithOr(outerClauses);
}
function parseMayIncorrectStatements(mayIncorrectStatements: MayIncorrectStatement[]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment