Skip to content

Commit

Permalink
Fix shuffle indices length mismatch error
Browse files Browse the repository at this point in the history
  • Loading branch information
naueramant committed May 22, 2024
1 parent ca977fb commit 61bb739
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utilities/deck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const GenerateDeck = (
numberOfPlayers: number,
): Card[] => {
if (shuffleIndices.length !== numberOfPlayers * CardValues.length - 1) {
throw new Error("Number of players and shuffle indices mismatch!");
throw new Error(
`Invalid shuffle indices length, got ${shuffleIndices.length}, expected ${numberOfPlayers * CardValues.length - 1}`,
);
}

const deck: Card[] = [];
Expand All @@ -29,7 +31,7 @@ const GenerateDeck = (
};

const GenerateShuffleIndices = (numberOfPlayers: number): number[] => {
const numberOfIndices = numberOfPlayers * CardValues.length;
const numberOfIndices = numberOfPlayers * CardValues.length - 1;

const shuffleIndices = [];
for (let i = numberOfIndices; i >= 1; i--) {
Expand Down

0 comments on commit 61bb739

Please sign in to comment.