Skip to content

Commit

Permalink
feat: add solution property in result
Browse files Browse the repository at this point in the history
BREAKING CHANGE
This commit introduces the solution feature that shows the steps taken to achieve the provided result
  • Loading branch information
Henry Hale committed Jan 7, 2024
1 parent d688001 commit 6f2ec67
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@
},
"packageManager": "pnpm@8.14.0",
"lint-staged": {
".ts": "pnpm lint"
"*.ts": "pnpm test"
}
}
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function generateSolution(raw: string[]) {
function step(str: string, box: string[]) {
let tmp = str;
if (str) {
tmp = str.replaceAll(/#\d/g, (m) => map[m]?.result || m);
tmp = str.replaceAll(/#\d/g, (m) => map[m]?.result || '');
box.unshift(tmp);
str = str.replaceAll(/#\d/g, (m) => map[m]?.expr || m);
str = str.replaceAll(/#\d/g, (m) => map[m]?.expr || '');
if (!str.includes('#')) {
box.unshift(str);
}
Expand Down
2 changes: 1 addition & 1 deletion test/interpreter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ describe('interpreter', () => {
const tokens = tokenize(expr);
const ast = parse(tokens);
const scope = { variables: { x: 1 } };
expect(interpret(ast, scope)).toBe(4);
expect(interpret(ast, scope, [], true)).toBe(4);
});
});

0 comments on commit 6f2ec67

Please sign in to comment.