Skip to content

Commit c063baa

Browse files
committed
Refactor: removed boolean variables and implemented the includes() method to simplify the code.
1 parent 477a236 commit c063baa

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

Sprint-3/1-implement-and-rewrite-tests/implement/3-get-card-value.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,7 @@ function getCardValue(card) {
2828
const suits = ["♠", "♥", "♦", "♣"];
2929
const suit = card[card.length - 1];
3030

31-
let suitValid = false;
32-
33-
for (let i = 0; i < suits.length; i++) {
34-
if (suit === suits[i]) {
35-
suitValid = true;
36-
break;
37-
}
38-
}
39-
// after comparing each suit in our array and does not match throw an error
40-
if (suitValid === false) {
31+
if (!suits.includes(suit)) {
4132
throw new Error("Invalid card suit");
4233
}
4334

0 commit comments

Comments
 (0)