1111// execute the code to ensure all tests pass.
1212
1313function isProperFraction ( numerator , denominator ) {
14- // TODO: Implement this function
14+ return Math . abs ( numerator ) < Math . abs ( denominator ) ;
1515}
1616
1717// The line below allows us to load the isProperFraction function into tests in other files.
@@ -31,3 +31,31 @@ function assertEquals(actualOutput, targetOutput) {
3131
3232// Example: 1/2 is a proper fraction
3333assertEquals ( isProperFraction ( 1 , 2 ) , true ) ;
34+
35+ // Basic non-proper examples
36+ assertEquals ( isProperFraction ( 2 , 1 ) , false ) ;
37+
38+ // Negative numerators or denominators should still use absolute values
39+ assertEquals ( isProperFraction ( - 1 , 2 ) , true ) ;
40+ assertEquals ( isProperFraction ( 1 , - 2 ) , true ) ;
41+ assertEquals ( isProperFraction ( - 1 , - 2 ) , true ) ;
42+
43+ // Zero numerator is a proper fraction when denominator != 0
44+ assertEquals ( isProperFraction ( 0 , 5 ) , true ) ;
45+
46+ // Equal magnitude (including signs) is not proper
47+ assertEquals ( isProperFraction ( 5 , 5 ) , false ) ;
48+ assertEquals ( isProperFraction ( - 5 , 5 ) , false ) ;
49+
50+ // Denominator zero (no division here, but should be considered invalid/proper=false)
51+ assertEquals ( isProperFraction ( 0 , 0 ) , false ) ;
52+ assertEquals ( isProperFraction ( 3 , 0 ) , false ) ;
53+
54+ // Larger values and decimals
55+ assertEquals ( isProperFraction ( 100 , 101 ) , true ) ;
56+ assertEquals ( isProperFraction ( 101 , 100 ) , false ) ;
57+ assertEquals ( isProperFraction ( 0.5 , 1 ) , true ) ;
58+ assertEquals ( isProperFraction ( 0.9999 , 1 ) , true ) ;
59+ assertEquals ( isProperFraction ( 1 , 1.0001 ) , true ) ;
60+
61+ console . log ( "Completed tests in 2-is-proper-fraction.js" ) ;
0 commit comments