Skip to content

Commit 9da6cfa

Browse files
committed
The 2-is-proper-fraction.js task has been solved
1 parent 3760f67 commit 9da6cfa

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/2-is-proper-fraction.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
// Written here like this: 1/2 == Numerator/Denominator
66
// the first test and first case is written for you
77
// complete the rest of the tests and cases
8-
// write one test at a time, and make it pass, build your solution up methodically
8+
// write one test at a time, and make it pass, build your solution up
99

1010
function isProperFraction(numerator, denominator) {
11+
if (denominator === 0) return false;
12+
if (numerator < 1) numerator = numerator * -1;
13+
if (denominator < 1) denominator = Math.abs(denominator);
14+
1115
if (numerator < denominator) {
1216
return true;
17+
} else {
18+
return false;
1319
}
1420
}
1521

@@ -47,13 +53,20 @@ assertEquals(improperFraction, false);
4753
// Explanation: The fraction -4/7 is a proper fraction because the absolute value of the numerator (4) is less than the denominator (7). The function should return true.
4854
const negativeFraction = isProperFraction(-4, 7);
4955
// ====> complete with your assertion
56+
assertEquals(negativeFraction, true);
5057

5158
// Equal Numerator and Denominator check:
5259
// Input: numerator = 3, denominator = 3
5360
// target output: false
5461
// Explanation: The fraction 3/3 is not a proper fraction because the numerator is equal to the denominator. The function should return false.
5562
const equalFraction = isProperFraction(3, 3);
5663
// ====> complete with your assertion
57-
64+
assertEquals(equalFraction, false);
5865
// Stretch:
5966
// What other scenarios could you test for?
67+
//Negative fraction check
68+
//Input: numerator=-4, denominator=2;
69+
//target output: false
70+
// Explanation: The fraction -4/2 is not a proper fraction because the absolute value of the numerator (4) is more than the denominator (2). The function should return false.
71+
const negativeFractionCase2 = isProperFraction(-4, 2);
72+
assertEquals(negativeFractionCase2, false);

0 commit comments

Comments
 (0)