Skip to content

Commit

Permalink
Javascript scoping bit me
Browse files Browse the repository at this point in the history
  • Loading branch information
benguaraldi committed Feb 25, 2022
1 parent ab807cc commit baccec1
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ export function getRandomItem(deck: Item[], played: Item[]): Item {
});

if (candidates.length > 0) {
const item = { ...candidates[Math.floor(Math.random() * candidates.length)] };
} else {
throw new Error("No item candidates");
const item = { ...deck[Math.floor(Math.random() * deck.length)] };
return candidates[Math.floor(Math.random() * candidates.length)];
}
return item;
throw new Error("No item candidates");
return deck[Math.floor(Math.random() * deck.length)];
}

function tooClose(item: Item, played: Item[]) {
Expand Down

0 comments on commit baccec1

Please sign in to comment.