Skip to content

Commit 70c2e4f

Browse files
completed function, wrote assertions and console.log to check
1 parent 61d68a8 commit 70c2e4f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
// execute the code to ensure all tests pass.
1212

1313
function isProperFraction(numerator, denominator) {
14-
// TODO: Implement this function
14+
if (denominator === 0) return false; // A fraction with a zero denominator is not valid
15+
if (Math.abs(numerator) >= Math.abs(denominator)) return false; // Not a proper fraction
16+
return true; // Is a proper fraction
1517
}
1618

1719
// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +33,15 @@ function assertEquals(actualOutput, targetOutput) {
3133

3234
// Example: 1/2 is a proper fraction
3335
assertEquals(isProperFraction(1, 2), true);
36+
assertEquals(isProperFraction(2, 2), false);
37+
assertEquals(isProperFraction(2, 1), false);
38+
assertEquals(isProperFraction(0, 2), true);
39+
assertEquals(isProperFraction(1, 0), false);
40+
assertEquals(isProperFraction(0, 0), false);
41+
42+
console.log(isProperFraction(1, 2));
43+
console.log(isProperFraction(2, 2));
44+
console.log(isProperFraction(2, 1));
45+
console.log(isProperFraction(0, 2));
46+
console.log(isProperFraction(1, 0));
47+
console.log(isProperFraction(0, 0));

0 commit comments

Comments
 (0)