Prevent getWeightedValue() function from null error if items and weights do not match

This commit is contained in:
Dev 2023-12-01 14:15:11 +00:00
parent 2a3839f6de
commit e1790ff7a5

View File

@ -22,6 +22,12 @@ export class WeightedRandomHelper
{
const itemKeys = Object.keys(itemArray);
const weights = Object.values(itemArray);
if (itemKeys.length !== weights.length)
{
return null;
}
const chosenItem = this.weightedRandom(itemKeys, weights);
return chosenItem.item;