Skip to content

Commit

Permalink
Fix invalid range problem with negative dice
Browse files Browse the repository at this point in the history
  • Loading branch information
juusaw committed Feb 15, 2019
1 parent bb6347b commit e24c418
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/dice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const roll = (sides: number) => Math.floor(Math.random() * sides + 1)

export function rollDice(dice: Dice[]) {
return dice.flatMap(([multiplier, sides]) => {
return new Array(multiplier).fill(undefined).map(() => roll(sides))
return new Array(Math.abs(multiplier))
.fill(undefined)
.map(() => multiplier / Math.abs(multiplier) * roll(sides))
})
}

Expand Down

0 comments on commit e24c418

Please sign in to comment.