File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed
Sprint-3/1-implement-and-rewrite-tests/implement Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -15,27 +15,26 @@ function getCardValue(card) {
1515 return false ;
1616 }
1717
18+ const pattern = / ^ (?: [ 2 - 9 ] | 1 0 ) $ / ;
1819 let rank = card . slice ( 0 , card . length - 1 ) ;
1920
2021 if ( strictNumber ( rank ) ) {
21- if (
22- Number . isInteger ( Number ( rank ) ) &&
23- Number ( rank ) > 1 &&
24- Number ( rank ) <= 10
25- ) {
22+ if ( pattern . test ( Number ( rank ) ) ) {
2623 return Number ( rank ) ;
2724 }
2825 }
2926
30- if ( rank . includes ( "J" ) || rank . includes ( "Q" ) || rank . includes ( "K" ) ) {
27+ const faceCardPattern = / ^ [ J Q K ] $ / ;
28+
29+ if ( faceCardPattern . test ( rank ) ) {
3130 return 10 ;
32- } else if ( rank . includes ( "A" ) ) {
31+ } else if ( / ^ A $ / . test ( rank ) ) {
3332 return 11 ;
3433 } else {
3534 return "Invalid card rank." ;
3635 }
3736}
38-
37+ console . log ( `Jack will give ${ getCardValue ( "J♥" ) } ` ) ;
3938// The line below allows us to load the getCardValue function into tests in other files.
4039// This will be useful in the "rewrite tests with jest" step.
4140module . exports = getCardValue ;
You can’t perform that action at this time.
0 commit comments