@khanacademy/perseus-score 0.0.0-PR875-20250221232857 → 0.0.0-PR875-20250225011257
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.
- package/dist/es/index.js +18 -0
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/es/index.js
CHANGED
|
@@ -229,6 +229,14 @@ const KhanAnswerTypes = {
|
|
|
229
229
|
},
|
|
230
230
|
// an improper fraction
|
|
231
231
|
improper: function (text) {
|
|
232
|
+
// As our answer keys are always in simplest form, we need
|
|
233
|
+
// to check for the existence of a fraction in the input before
|
|
234
|
+
// validating the answer. If no fraction is found, we consider
|
|
235
|
+
// the answer to be incorrect.
|
|
236
|
+
const fractionExists = text.includes("/") || text.match(/\\(d?frac)/);
|
|
237
|
+
if (!fractionExists) {
|
|
238
|
+
return [];
|
|
239
|
+
}
|
|
232
240
|
return $.map(fractionTransformer(text), function (o) {
|
|
233
241
|
// All fractions that are greater than 1
|
|
234
242
|
if (Math.abs(o.value) >= 1) {
|
|
@@ -1456,6 +1464,16 @@ function parseNextExpression(tex, currentIndex, handler) {
|
|
|
1456
1464
|
// Find the first '{' and grab subsequent TeX
|
|
1457
1465
|
// Ex) tex: '{3}{7}', and we want the '3'
|
|
1458
1466
|
const openBracketIndex = tex.indexOf("{", currentIndex);
|
|
1467
|
+
|
|
1468
|
+
// If there is no open bracket, set the endpoint to the end of the string
|
|
1469
|
+
// and the expression to an empty string. This helps ensure we don't
|
|
1470
|
+
// get stuck in an infinite loop when users handtype TeX.
|
|
1471
|
+
if (openBracketIndex === -1) {
|
|
1472
|
+
return {
|
|
1473
|
+
endpoint: tex.length,
|
|
1474
|
+
expression: ""
|
|
1475
|
+
};
|
|
1476
|
+
}
|
|
1459
1477
|
const nextExpIndex = openBracketIndex + 1;
|
|
1460
1478
|
|
|
1461
1479
|
// Truncate to only contain remaining TeX
|