diff --git a/src/dice.ts b/src/dice.ts index 91718fa..bebc616 100644 --- a/src/dice.ts +++ b/src/dice.ts @@ -24,7 +24,7 @@ function validateDiceString(input: string): boolean { function diceToDieArr({ amount, sides }: Dice): Die[] { if (amount === 0) return [] - return new Array(Math.abs(amount)).fill(amount / Math.abs(amount) * sides) + return new Array(Math.abs(amount)).fill({sides: amount / Math.abs(amount) * sides}) } export function parseDice(inputStr: string): Dice[] | null { @@ -74,7 +74,7 @@ export function calculateMin(dice: Dice[]) { } export function getDistribution(dice: Dice[]) { - const diceRanges = dice.flatMap(diceToDieArr).map(rangeTo) + const diceRanges = dice.flatMap(diceToDieArr).map(die => rangeTo(die.sides)) const possibleResults = cartesian(diceRanges) return possibleResults.map(resultArr => resultArr.reduce((a, b) => a + b, 0)).sort((a, b) => a - b) } diff --git a/src/utils.ts b/src/utils.ts index 3ab5170..6e978ed 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -export function rangeTo(n) { +export function rangeTo(n: number) { if (n === 0) return [] return new Array(Math.abs(n)).fill(undefined).map((_, i) => n / Math.abs(n) * (i + 1)) } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..37a23fc --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES2016", + "module": "commonjs", + "sourceMap": false, + "strict": true, + "esModuleInterop": true, + "inlineSourceMap": false, + "inlineSources": false + } +} \ No newline at end of file