File tree Expand file tree Collapse file tree 2 files changed +25
-7
lines changed
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree 2 files changed +25
-7
lines changed Original file line number Diff line number Diff line change 99
1010function isProperFraction ( numerator , denominator ) {
1111 // Case 1 & general case: numerator < denominator
12- if ( Math . abs ( numerator ) < denominator ) {
12+ if ( Math . abs ( numerator ) < Math . abs ( denominator ) ) {
1313 return true ;
1414 } else {
1515 return false ;
Original file line number Diff line number Diff line change @@ -22,14 +22,32 @@ function getCardValue(card) {
2222 return 10 ;
2323 }
2424
25- // Handle number cards 2-9
26- const num = Number ( rank ) ;
27- if ( num >= 2 && num <= 9 ) {
28- return num ;
25+ // Handle number cards 2-10
26+ const validRanks = [
27+ "A" ,
28+ "2" ,
29+ "3" ,
30+ "4" ,
31+ "5" ,
32+ "6" ,
33+ "7" ,
34+ "8" ,
35+ "9" ,
36+ "10" ,
37+ "J" ,
38+ "Q" ,
39+ "K" ,
40+ ] ;
41+
42+ // Check if rank is valid
43+ if ( ! validRanks . includes ( rank ) ) {
44+ throw new Error ( "Invalid card rank." ) ;
2945 }
3046
31- // Invalid card
32- throw new Error ( "Invalid card rank." ) ;
47+ // Return correct values
48+ if ( rank === "A" ) return 11 ;
49+ if ( [ "J" , "Q" , "K" ] . includes ( rank ) ) return 10 ;
50+ return Number ( rank ) ; // for 2–10
3351}
3452
3553// The line below allows us to load the getCardValue function into tests in other files.
You can’t perform that action at this time.
0 commit comments