@@ -18,68 +18,14 @@ function getCardValue(card) {
1818 // Face cards
1919 if ( [ "J" , "Q" , "K" ] . includes ( rank ) ) return 10 ;
2020
21- // Number cards (STRICT check)
22- const validNumbers = [ "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" ] ;
21+ // Number cards
22+ const validNumbers = [ "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" ] ;
2323
2424 if ( validNumbers . includes ( rank ) ) {
2525 return Number ( rank ) ;
2626 }
2727
28- // Everything else = invalid
2928 throw new Error ( "Invalid card" ) ;
3029}
3130
32- << < << << HEAD
33- module . exports = getCardValue ;
34- = === ===
35- // The line below allows us to load the getCardValue function into tests in other files.
36- // This will be useful in the "rewrite tests with jest" step.
37- module . exports = getCardValue ;
38-
39- // Helper functions to make our assertions easier to read.
40- function assertEquals ( actualOutput , targetOutput ) {
41- console . assert (
42- actualOutput === targetOutput ,
43- `Expected ${ actualOutput } to equal ${ targetOutput } `
44- ) ;
45- }
46-
47- // TODO: Write tests to cover all outcomes, including throwing errors for invalid cards.
48- // Examples:
49- assertEquals ( getCardValue ( "9♠" ) , 9 ) ;
50-
51- // Ace
52- assertEquals ( getCardValue ( "A♠" ) , 11 ) ;
53-
54- // Face cards
55- assertEquals ( getCardValue ( "J♥" ) , 10 ) ;
56- assertEquals ( getCardValue ( "Q♦" ) , 10 ) ;
57- assertEquals ( getCardValue ( "K♣" ) , 10 ) ;
58-
59- // Number cards
60- assertEquals ( getCardValue ( "2♠" ) , 2 ) ;
61- assertEquals ( getCardValue ( "10♥" ) , 10 ) ;
62-
63- // Handling invalid cards
64- try {
65- getCardValue ( "invalid" ) ;
66-
67- // This line will not be reached if an error is thrown as expected
68- console . error ( "Error was not thrown for invalid card 😢" ) ;
69- } catch ( e ) {
70- console . log ( "Error thrown for invalid card 🎉" ) ;
71- }
72-
73- // More invalid cases
74- try {
75- getCardValue ( "11♠" ) ;
76- console . error ( "Error was not thrown for invalid card" ) ;
77- } catch ( e ) { }
78-
79- try {
80- getCardValue ( "A" ) ;
81- console . error ( "Error was not thrown for invalid card" ) ;
82- } catch ( e ) { }
83-
84- // What other invalid card cases can you think of?
85- > >>> >>> 983743526 bc0a40a31b8e20926f23fa3ceb5cf29
31+ module . exports = getCardValue ;
0 commit comments