1212
1313function isProperFraction ( numerator , denominator ) {
1414 // TODO: Implement this function
15+ if ( denominator === 0 ) {
16+ return false ; // A fraction with a denominator of 0 is undefined, so it's not a proper fraction.
17+ }
18+ if ( Math . abs ( numerator ) < Math . abs ( denominator ) ) {
19+ return true ; // A proper fraction has an absolute value of the numerator less than the absolute value of the denominator.
20+ }
21+ return false ; // If none of the above conditions are met, it's not a proper fraction.
1522}
1623
1724// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +38,30 @@ function assertEquals(actualOutput, targetOutput) {
3138
3239// Example: 1/2 is a proper fraction
3340assertEquals ( isProperFraction ( 1 , 2 ) , true ) ;
41+
42+ // Example: -1/2 is a proper fraction
43+ assertEquals ( isProperFraction ( - 1 , 2 ) , true ) ;
44+
45+ // Example: 1/-2 is a proper fraction
46+ assertEquals ( isProperFraction ( 1 , - 2 ) , true ) ;
47+
48+ // Example: -1/-2 is a proper fraction
49+ assertEquals ( isProperFraction ( - 1 , - 2 ) , true ) ;
50+
51+ // Example: 2/1 is not a proper fraction
52+ assertEquals ( isProperFraction ( 2 , 1 ) , false ) ;
53+
54+ // Example: -2/1 is not a proper fraction
55+ assertEquals ( isProperFraction ( - 2 , 1 ) , false ) ;
56+
57+ // Example: 0/1 is a proper fraction
58+ assertEquals ( isProperFraction ( 0 , 1 ) , true ) ;
59+
60+ // Example: 1/0 is not a proper fraction (undefined)
61+ assertEquals ( isProperFraction ( 1 , 0 ) , false ) ;
62+
63+ // Example: -1/0 is not a proper fraction (undefined)
64+ assertEquals ( isProperFraction ( - 1 , 0 ) , false ) ;
65+
66+ // Example: 0/0 is not a proper fraction (undefined)
67+ assertEquals ( isProperFraction ( 0 , 0 ) , false ) ;
0 commit comments