Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29,635 changes: 17,507 additions & 12,128 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"dependencies": {
"@types/jest": "24.0.18",
"@types/node": "12.7.2",
"@types/react": "16.9.2",
"@types/react-dom": "16.8.5",
"@types/react": "18.3.5",
"@types/react-dom": "18.3.0",
"gh-pages": "^2.1.1",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-scripts": "^3.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-scripts": "^5.0.1",
"typescript": "3.5.3"
},
"scripts": {
Expand Down
34 changes: 34 additions & 0 deletions src/calculateHandValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {Card} from './sharedTypes'

const faceCards = ['K', 'Q', 'J']

const calculateHandValue = (cards: Card[]) => {
let total = 0;
const visibleCards = cards.filter(card => !card.hidden)
visibleCards.forEach((card) => {
if (card.value !== 'A') {
total += faceCards.includes(card.value) ? 10 : Number(card.value);
}
});
const aces = visibleCards.filter((card) => card.value === 'A');
aces.forEach((card) => {
if ((total + 11) > 21) {
total += 1;
}
else if ((total + 11) === 21) {
if (aces.length > 1) {
total += 1;
}
else {
total += 11;
}
}
else {
total += 11;
}
});

return total;
}

export default calculateHandValue
Loading