mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 12:37:00 +03:00
Fix undefined issue
This commit is contained in:
@@ -177,9 +177,17 @@ function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOf
|
|||||||
weight: number
|
weight: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let forceIncludedChoices: T[] = [];
|
||||||
|
let filteredChoices = choices;
|
||||||
|
if (predicate) {
|
||||||
|
const splitArray = partition(choices, predicate);
|
||||||
|
filteredChoices = splitArray[0];
|
||||||
|
forceIncludedChoices = splitArray[1];
|
||||||
|
}
|
||||||
|
|
||||||
//assign a weight to each choice
|
//assign a weight to each choice
|
||||||
let totalWeight = 0;
|
let totalWeight = 0;
|
||||||
let choicesWithWeights: TWithWeight[] = choices.map(choice => {
|
const choicesWithWeights: TWithWeight[] = filteredChoices.map(choice => {
|
||||||
const boost = Math.min(choice.reputation, 4);
|
const boost = Math.min(choice.reputation, 4);
|
||||||
|
|
||||||
//The 3 makes -2 the minimum votes before being ignored completely
|
//The 3 makes -2 the minimum votes before being ignored completely
|
||||||
@@ -190,13 +198,6 @@ function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOf
|
|||||||
return { ...choice, weight };
|
return { ...choice, weight };
|
||||||
});
|
});
|
||||||
|
|
||||||
let forceIncludedChoices: T[] = [];
|
|
||||||
if (predicate) {
|
|
||||||
const splitArray = partition(choicesWithWeights, predicate);
|
|
||||||
choicesWithWeights = splitArray[0];
|
|
||||||
forceIncludedChoices = splitArray[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nothing to filter for
|
// Nothing to filter for
|
||||||
if (amountOfChoices >= choicesWithWeights.length) {
|
if (amountOfChoices >= choicesWithWeights.length) {
|
||||||
return choices;
|
return choices;
|
||||||
|
|||||||
Reference in New Issue
Block a user