File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
Sprint-3/2-mandatory-rewrite Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change 1
1
function isProperFraction ( numerator , denominator ) {
2
2
if ( numerator < denominator ) return true ;
3
3
// add your completed function from key-implement here
4
+ //return denominator !== 0 && Math.abs(numerator) < Math.abs(denominator);
5
+ if ( denominator === 0 ) return false ; // Avoid division by zero
6
+ if ( numerator === 0 ) return true ; // Zero is considered a proper fraction
7
+ if ( numerator < 0 || denominator < 0 ) return false ; // Negative fractions are not proper
8
+ return Math . abs ( numerator ) < Math . abs ( denominator ) ;
9
+
10
+
4
11
}
5
12
6
- module . exports = isProperFraction ;
13
+ console . log ( isProperFraction ( 0 , 1 ) ) ;
14
+
15
+ module . exports = isProperFraction ;
16
+
Original file line number Diff line number Diff line change @@ -2,10 +2,23 @@ const isProperFraction = require("./2-is-proper-fraction");
2
2
3
3
test ( "should return true for a proper fraction" , ( ) => {
4
4
expect ( isProperFraction ( 2 , 3 ) ) . toEqual ( true ) ;
5
+ expect ( isProperFraction ( 1 , 2 ) ) . toEqual ( true ) ;
5
6
} ) ;
6
7
7
8
// Case 2: Identify Improper Fractions:
9
+ test ( "should return false for an improper fraction" , ( ) => {
10
+ expect ( isProperFraction ( 5 , 3 ) ) . toEqual ( false ) ;
11
+ expect ( isProperFraction ( 3 , 3 ) ) . toEqual ( false ) ;
12
+ } ) ;
13
+
8
14
9
15
// Case 3: Identify Negative Fractions:
16
+ test ( "should return false for a negative fraction" , ( ) => {
17
+ //expect(isProperFraction(-2, 3)).toEqual(false);
18
+ expect ( isProperFraction ( 2 , - 3 ) ) . toEqual ( false ) ;
19
+ expect ( isProperFraction ( - 2 , - 3 ) ) . toEqual ( false ) ; // consider your spec on this one
20
+ } ) ;
21
+
22
+
23
+
10
24
11
- // Case 4: Identify Equal Numerator and Denominator:
You can’t perform that action at this time.
0 commit comments