Skip to content

Commit 26ac72d

Browse files
authored
style: simplify binaryLCM (#233)
1 parent b3a3bd7 commit 26ac72d

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

maths/lowest_common_multiple.ts

-8
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ export const naiveLCM = (nums: number[]): number => {
3838
//Note that due to utilizing GCF, which requires natural numbers, this method only accepts natural numbers.
3939

4040
export const binaryLCM = (a: number, b: number): number => {
41-
if (a < 0 || b < 0) {
42-
throw new Error("numbers must be positive to determine lowest common multiple");
43-
}
44-
45-
if (!Number.isInteger(a) || !Number.isInteger(b)) {
46-
throw new Error("this method, which utilizes GCF, requires natural numbers.");
47-
}
48-
4941
return a * b / greatestCommonFactor([a, b]);
5042
}
5143

maths/test/lowest_common_multiple.test.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ describe("binaryLCM", () => {
2929
},
3030
);
3131

32-
test("only whole numbers should be accepted", () => {
33-
expect(() => binaryLCM(-2, -3)).toThrowError(
34-
"numbers must be positive to determine lowest common multiple",
35-
);
32+
test("only natural numbers should be accepted", () => {
33+
expect(() => binaryLCM(-2, -3)).toThrowError();
34+
expect(() => binaryLCM(2, -3)).toThrowError();
35+
expect(() => binaryLCM(-2, 3)).toThrowError();
36+
});
37+
38+
test("should throw when any of the inputs is not an int", () => {
39+
expect(() => binaryLCM(1, 2.5)).toThrowError();
40+
expect(() => binaryLCM(1.5, 2)).toThrowError();
3641
});
3742
});
3843

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

4752
test("only positive numbers should be accepted", () => {
48-
expect(() => lowestCommonMultiple([-2, -3])).toThrowError(
49-
"numbers must be positive to determine lowest common multiple",
50-
);
53+
expect(() => lowestCommonMultiple([-2, -3])).toThrowError();
5154
});
5255

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

0 commit comments

Comments
 (0)