Skip to content

Commit cc10398

Browse files
committed
wrote the code for 2-is-proper-function of sprint-3 and test cases
1 parent 088f2bd commit cc10398

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@
1212

1313
function isProperFraction(numerator, denominator) {
1414
// TODO: Implement this function
15+
if (denominator === 0) {
16+
return false;
17+
}
18+
if (numerator < 0 && denominator < 0) {
19+
return Math.abs(numerator) < Math.abs(denominator);
20+
}
21+
if (numerator < 0 || denominator < 0) {
22+
return false;
23+
}
24+
return numerator < denominator;
1525
}
1626

1727
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +41,10 @@ function assertEquals(actualOutput, targetOutput) {
3141

3242
// Example: 1/2 is a proper fraction
3343
assertEquals(isProperFraction(1, 2), true);
44+
assertEquals(isProperFraction(2, 1), false);
45+
assertEquals(isProperFraction(0, 1), true);
46+
assertEquals(isProperFraction(-1, 2), false);
47+
assertEquals(isProperFraction(1, -2), false);
48+
assertEquals(isProperFraction(-1, -2), false);
49+
assertEquals(isProperFraction(3, 4), true);
50+
assertEquals(isProperFraction(4, 3), false);

0 commit comments

Comments
 (0)