CONTRACTS: Display contract answers on completely failed contracts (#2440)

This commit is contained in:
Adam Weeden
2026-01-08 16:21:52 -05:00
committed by GitHub
parent edf3d11b72
commit 7af9dca6bc
23 changed files with 221 additions and 48 deletions

View File

@@ -1,3 +1,4 @@
import { exceptionAlert } from "../../utils/helpers/exceptionAlert";
import { getRandomIntInclusive } from "../../utils/helpers/getRandomIntInclusive";
import { CodingContractTypes, removeBracketsFromArrayString, removeQuotesFromString } from "../ContractTypes";
import { CodingContractName } from "@enums";
@@ -45,7 +46,7 @@ export const sanitizeParenthesesInExpression: Pick<
return chars.join("");
},
solver: (data, answer) => {
getAnswer: (data) => {
let left = 0;
let right = 0;
const res: string[] = [];
@@ -94,6 +95,20 @@ export const sanitizeParenthesesInExpression: Pick<
dfs(0, 0, left, right, data, "", res);
return res;
},
solver: (data, answer) => {
const res = sanitizeParenthesesInExpression[CodingContractName.SanitizeParenthesesInExpression].getAnswer(data);
if (res === null) {
exceptionAlert(
new Error(
`Unexpected null when calculating the answer for ${CodingContractName.SanitizeParenthesesInExpression} contract. Data: ${data}`,
),
);
return false;
}
if (res.length !== answer.length) return false;
return res.every((sol) => answer.includes(sol));
},