fractions add/sub fix
This commit is contained in:
@@ -15,6 +15,20 @@ export function parseStrictInt(input: string): number | null {
|
||||
return parseInt(s, 10);
|
||||
}
|
||||
|
||||
/** Parse a strict signed integer string. Reject decimals, scientific notation, and trailing text. */
|
||||
export function parseStrictSignedInt(input: string): number | null {
|
||||
const s = input.trim();
|
||||
if (!/^-?\d+$/.test(s)) return null;
|
||||
return parseInt(s, 10);
|
||||
}
|
||||
|
||||
/** Parse a strict signed decimal string. Reject scientific notation and trailing text. */
|
||||
export function parseStrictSignedDecimal(input: string): number | null {
|
||||
const s = input.trim();
|
||||
if (!/^-?\d+(\.\d+)?$/.test(s)) return null;
|
||||
return parseFloat(s);
|
||||
}
|
||||
|
||||
export type AnswerResult =
|
||||
| { correct: true; simplified: boolean }
|
||||
| { correct: false; message: string };
|
||||
@@ -37,6 +51,11 @@ export function checkFractionAnswer(
|
||||
return { correct: false, message: "That's not quite right. Try again!" };
|
||||
}
|
||||
|
||||
// Any non-zero denominator gives the same value for zero, so don't force 0/1 in the UI.
|
||||
if (userNum === 0) {
|
||||
return { correct: true, simplified: true };
|
||||
}
|
||||
|
||||
const isSimplified = gcd(Math.abs(userNum), Math.abs(userDen)) === 1;
|
||||
|
||||
if (requireSimplified && !isSimplified) {
|
||||
|
||||
Reference in New Issue
Block a user