Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions maths/lowest_common_multiple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ export const naiveLCM = (nums: number[]): number => {
//Note that due to utilizing GCF, which requires natural numbers, this method only accepts natural numbers.

export const binaryLCM = (a: number, b: number): number => {
if (a < 0 || b < 0) {
throw new Error("numbers must be positive to determine lowest common multiple");
}

if (!Number.isInteger(a) || !Number.isInteger(b)) {
throw new Error("this method, which utilizes GCF, requires natural numbers.");
}

return a * b / greatestCommonFactor([a, b]);
}

Expand Down
17 changes: 10 additions & 7 deletions maths/test/lowest_common_multiple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ describe("binaryLCM", () => {
},
);

test("only whole numbers should be accepted", () => {
expect(() => binaryLCM(-2, -3)).toThrowError(
"numbers must be positive to determine lowest common multiple",
);
test("only natural numbers should be accepted", () => {
expect(() => binaryLCM(-2, -3)).toThrowError();
expect(() => binaryLCM(2, -3)).toThrowError();
expect(() => binaryLCM(-2, 3)).toThrowError();
});

test("should throw when any of the inputs is not an int", () => {
expect(() => binaryLCM(1, 2.5)).toThrowError();
expect(() => binaryLCM(1.5, 2)).toThrowError();
});
});

Expand All @@ -45,9 +50,7 @@ describe("lowestCommonMultiple", () => {
);

test("only positive numbers should be accepted", () => {
expect(() => lowestCommonMultiple([-2, -3])).toThrowError(
"numbers must be positive to determine lowest common multiple",
);
expect(() => lowestCommonMultiple([-2, -3])).toThrowError();
});

test("at least one number must be passed in", () => {
Expand Down