fix issues
This commit is contained in:
parent
835efb31b9
commit
6a406db60a
23 changed files with 295 additions and 118 deletions
|
@ -65,7 +65,7 @@ function assignSubChecksToDice(
|
|||
|
||||
function findIndexOfSmallestNonCoup(dice: number[], maximumCoupResult: number): number {
|
||||
return dice
|
||||
.map((die, index) => [die, index])
|
||||
.map((die, index): [number, number] => [die, index])
|
||||
.filter((indexedDie) => indexedDie[0] > maximumCoupResult)
|
||||
.reduce(
|
||||
(smallestIndexedDie, indexedDie) =>
|
||||
|
@ -77,14 +77,25 @@ function findIndexOfSmallestNonCoup(dice: number[], maximumCoupResult: number):
|
|||
function shouldUseCoupForLastSubCheck(
|
||||
indexOfSmallestNonCoup: number,
|
||||
indexOfFirstCoup: number,
|
||||
dice: number[],
|
||||
dice: readonly number[],
|
||||
checkTargetNumberForLastSubCheck: number,
|
||||
) {
|
||||
if (indexOfFirstCoup !== -1 && indexOfSmallestNonCoup === -1) {
|
||||
return true;
|
||||
}
|
||||
const smallestNonCoup = dice[indexOfSmallestNonCoup];
|
||||
if (
|
||||
!Number.isInteger(indexOfFirstCoup) ||
|
||||
indexOfFirstCoup < -1 ||
|
||||
!Number.isInteger(indexOfSmallestNonCoup) ||
|
||||
smallestNonCoup === undefined
|
||||
) {
|
||||
throw new Error("Received an invalid value for the parameter indexOfSmallestNonCoup or indexOfFirstCoup,");
|
||||
}
|
||||
return (
|
||||
indexOfFirstCoup !== -1 &&
|
||||
(indexOfSmallestNonCoup === -1 ||
|
||||
(dice[indexOfSmallestNonCoup] > checkTargetNumberForLastSubCheck &&
|
||||
dice[indexOfSmallestNonCoup] + checkTargetNumberForLastSubCheck > 20))
|
||||
smallestNonCoup > checkTargetNumberForLastSubCheck &&
|
||||
smallestNonCoup + checkTargetNumberForLastSubCheck > 20
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue