mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-06 11:36:58 +03:00
Fix undefined issue
This commit is contained in:
@@ -177,9 +177,17 @@ function getWeightedRandomChoice<T extends VotableObject>(choices: T[], amountOf
|
||||
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
|
||||
let totalWeight = 0;
|
||||
let choicesWithWeights: TWithWeight[] = choices.map(choice => {
|
||||
const choicesWithWeights: TWithWeight[] = filteredChoices.map(choice => {
|
||||
const boost = Math.min(choice.reputation, 4);
|
||||
|
||||
//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 };
|
||||
});
|
||||
|
||||
let forceIncludedChoices: T[] = [];
|
||||
if (predicate) {
|
||||
const splitArray = partition(choicesWithWeights, predicate);
|
||||
choicesWithWeights = splitArray[0];
|
||||
forceIncludedChoices = splitArray[1];
|
||||
}
|
||||
|
||||
// Nothing to filter for
|
||||
if (amountOfChoices >= choicesWithWeights.length) {
|
||||
return choices;
|
||||
|
||||
Reference in New Issue
Block a user