| 86 | * the hand, if, for instance, there are no triples. |
| 87 | */ |
| 88 | export function handScoringHelper(hand) { |
| 89 | // Create an array of all zeros of the appropriate size. |
| 90 | const faceValOfEachGroup = []; |
| 91 | for (let i = 0; i < GAME_STATE.num_cards_per_hand; i++) { |
| 92 | faceValOfEachGroup.push(0); |
| 93 | } |
| 94 | let runLength = 0; |
| 95 | let prevVal = 0; |
| 96 | for (let i = 0; i < GAME_STATE.num_cards_per_hand; i++) { |
| 97 | const card = hand[i]; |
| 98 | if (card == prevVal) { |
| 99 | runLength += 1; |
| 100 | } else { |
| 101 | prevVal = card; |
| 102 | runLength = 1; |
| 103 | } |
| 104 | faceValOfEachGroup[runLength - 1] = card; |
| 105 | } |
| 106 | return faceValOfEachGroup; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns 1 if hand1 beats hand2, in terms of hand value. |