math-exercises 3.0.65 → 3.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"findProportion.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/percent/findProportion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAQrC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAkFF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAehD,CAAC"}
1
+ {"version":3,"file":"findProportion.d.ts","sourceRoot":"","sources":["../../../../src/exercises/math/percent/findProportion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EAcT,MAAM,6BAA6B,CAAC;AAYrC,KAAK,WAAW,GAAG;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAgGF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,WAAW,CAehD,CAAC"}
@@ -1,8 +1,12 @@
1
1
  import { addValidProp, shuffleProps, tryToAddWrongProp, } from "../../../exercises/exercise.js";
2
2
  import { getDistinctQuestions } from "../../../exercises/utils/getDistinctQuestions.js";
3
+ import { rationalVEA } from "../../../exercises/vea/rationalVEA.js";
3
4
  import { randfloat } from "../../../math/utils/random/randfloat.js";
4
5
  import { randint } from "../../../math/utils/random/randint.js";
5
6
  import { round } from "../../../math/utils/round.js";
7
+ import { frac } from "../../../tree/nodes/operators/fractionNode.js";
8
+ import { percentParser } from "../../../tree/parsers/percentParser.js";
9
+ import { handleVEAError } from "../../../utils/errors/handleVEAError.js";
6
10
  import { approxOrEqual } from "../../../utils/latex/approxOrEqual.js";
7
11
  const getInstruction = (identifiers) => {
8
12
  const { total, lefties } = identifiers;
@@ -60,7 +64,23 @@ const getPropositions = (n, { answer, total, lefties }) => {
60
64
  }
61
65
  return shuffleProps(propositions, n);
62
66
  };
63
- const isAnswerValid = (ans, { answer }) => {
67
+ const isAnswerValid = (ans, { answer, lefties, total }) => {
68
+ try {
69
+ if (ans.includes("\\%")) {
70
+ return percentParser(ans) === answer;
71
+ }
72
+ const nb = ans.unfrenchify();
73
+ if (!isNaN(nb)) {
74
+ const value = answer.replace("\\%", "").unfrenchify();
75
+ return nb === value || nb === round(value / 100, 4);
76
+ }
77
+ else {
78
+ return rationalVEA(ans, frac(lefties, total).simplify().toTex());
79
+ }
80
+ }
81
+ catch (err) {
82
+ return handleVEAError(err);
83
+ }
64
84
  const texs = [answer, answer.replace("\\%", "")];
65
85
  return texs.includes(ans);
66
86
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "math-exercises",
3
3
  "type": "module",
4
- "version": "3.0.65",
4
+ "version": "3.0.66",
5
5
  "description": "Math exercises generator for middle school and high school",
6
6
  "main": "lib/index.js",
7
7
  "files": [