Fix bug in Fraction.lcm (#1133)

* bugfix lcm
This commit is contained in:
Alex McLean 2024-06-18 22:58:08 +01:00 committed by GitHub
parent 6350cfdb9c
commit 283a071c86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 2 deletions

View file

@ -119,10 +119,10 @@ export const lcm = (...fractions) => {
if (fractions.length === 0) {
return undefined;
}
const x = fractions.pop();
return fractions.reduce(
(lcm, fraction) => (lcm === undefined || fraction === undefined ? undefined : lcm.lcm(fraction)),
fraction(1),
x,
);
};