1212
1313function isProperFraction ( numerator , denominator ) {
1414 // TODO: Implement this function
15- }
1615
16+ if ( denominator === 0 ) {
17+ return false ; // A fraction with a denominator of 0 is undefined, so it's not a proper fraction.
18+ }
19+ if ( numerator === 0 ) {
20+ return true ; // A fraction with a numerator of 0 is a proper fraction (0/1 = 0).
21+ }
22+ if ( Math . abs ( numerator ) < Math . abs ( denominator ) ) {
23+ return true ; // If the absolute value of the numerator is less than the absolute value of the denominator,
24+ // it's a proper fraction.
25+ }
26+ return false ; // Otherwise, it's not a proper fraction.
27+ }
1728// The line below allows us to load the isProperFraction function into tests in other files.
1829// This will be useful in the "rewrite tests with jest" step.
1930module . exports = isProperFraction ;
@@ -31,3 +42,15 @@ function assertEquals(actualOutput, targetOutput) {
3142
3243// Example: 1/2 is a proper fraction
3344assertEquals ( isProperFraction ( 1 , 2 ) , true ) ;
45+
46+ // Example: 2/1 is not a proper fraction
47+ assertEquals ( isProperFraction ( 2 , 1 ) , false ) ;
48+
49+ // Example: 0/5 is a proper fraction
50+ assertEquals ( isProperFraction ( 0 , 5 ) , true ) ;
51+
52+ // Example: -5/10 is a proper fraction
53+ assertEquals ( isProperFraction ( - 5 , 10 ) , true ) ;
54+
55+ // Example: 0/0 is not a proper fraction
56+ assertEquals ( isProperFraction ( 0 , 0 ) , false ) ;
0 commit comments