1111// execute the code to ensure all tests pass.
1212
1313function isProperFraction ( numerator , denominator ) {
14- if ( Number . isFinite ( numerator ) && Number . isFinite ( denominator ) ) {
15- if ( numerator < denominator ) {
16- return true
17- }
18- } return false
14+ return denominator !== 0 && Math . abs ( numerator / denominator ) < 1 ;
1915}
2016
2117// The line below allows us to load the isProperFraction function into tests in other files.
@@ -24,10 +20,10 @@ module.exports = isProperFraction;
2420
2521// Here's our helper again
2622function assertEquals ( actualOutput , targetOutput ) {
27- console . assert (
28- actualOutput === targetOutput ,
29- `Expected ${ actualOutput } to equal ${ targetOutput } `
30- ) ;
23+ console . assert (
24+ actualOutput === targetOutput ,
25+ `Expected ${ actualOutput } to equal ${ targetOutput } `
26+ ) ;
3127}
3228
3329// What combinations of numerators and denominators should you test?
@@ -40,20 +36,9 @@ assertEquals(isProperFraction(0, 5), true);
4036assertEquals ( isProperFraction ( 5 , 0 ) , false ) ;
4137assertEquals ( isProperFraction ( 0 , 0 ) , false ) ;
4238assertEquals ( isProperFraction ( - 1 , 2 ) , true ) ;
43- assertEquals ( isProperFraction ( 1 , - 2 ) , false ) ;
44- assertEquals ( isProperFraction ( - 2 , - 1 ) , true ) ;
45- assertEquals ( isProperFraction ( - 1 , - 2 ) , false ) ;
39+ assertEquals ( isProperFraction ( 1 , - 2 ) , true ) ;
40+ assertEquals ( isProperFraction ( - 2 , - 1 ) , false ) ;
41+ assertEquals ( isProperFraction ( - 1 , - 2 ) , true ) ;
4642assertEquals ( isProperFraction ( 0.5 , 1 ) , true ) ;
4743assertEquals ( isProperFraction ( 1.5 , 1 ) , false ) ;
48- assertEquals ( isProperFraction ( Infinity , 2 ) , false ) ;
49- assertEquals ( isProperFraction ( 2 , Infinity ) , false ) ;
50- assertEquals ( isProperFraction ( NaN , 2 ) , false ) ;
51- assertEquals ( isProperFraction ( 2 , NaN ) , false ) ;
5244assertEquals ( isProperFraction ( 999999999 , 1000000000 ) , true ) ;
53-
54-
55-
56-
57-
58-
59-
0 commit comments