Prevent getWeightedValue()
function from null error if items and weights do not match
This commit is contained in:
parent
2a3839f6de
commit
e1790ff7a5
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user