1111// execute the code to ensure all tests pass.
1212
1313function isProperFraction ( numerator , denominator ) {
14- // TODO: Implement this function
14+ // A fraction with denominator 0 is invalid
15+ if ( denominator === 0 ) {
16+ return false ;
17+ }
18+
19+ // A proper fraction has absolute numerator smaller than absolute denominator
20+ if ( Math . abs ( numerator ) < Math . abs ( denominator ) ) {
21+ return true ;
22+ }
23+
24+ return false ;
1525}
1626
1727// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +41,19 @@ function assertEquals(actualOutput, targetOutput) {
3141
3242// Example: 1/2 is a proper fraction
3343assertEquals ( isProperFraction ( 1 , 2 ) , true ) ;
44+
45+ // Proper fractions
46+ assertEquals ( isProperFraction ( 3 , 5 ) , true ) ;
47+ assertEquals ( isProperFraction ( - 2 , 7 ) , true ) ;
48+ assertEquals ( isProperFraction ( 2 , - 7 ) , true ) ;
49+
50+ // Improper fractions
51+ assertEquals ( isProperFraction ( 5 , 5 ) , false ) ;
52+ assertEquals ( isProperFraction ( 7 , 3 ) , false ) ;
53+ assertEquals ( isProperFraction ( - 8 , 4 ) , false ) ;
54+
55+ // Zero numerator
56+ assertEquals ( isProperFraction ( 0 , 5 ) , true ) ;
57+
58+ // Invalid fraction (denominator 0)
59+ assertEquals ( isProperFraction ( 2 , 0 ) , false ) ;
0 commit comments