-
-
Save Balastrong/e0aef8b0889616c6bdcc3fe749e219ce to your computer and use it in GitHub Desktop.
wrand - randomGenerator validate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private validate(items: WeightedItem<T>[]) { | |
if (items.length === 0) { | |
throw new Error("Items list is empty!"); | |
} | |
const set = new Set(); | |
for (const item of items) { | |
if (item.weight <= 0) { | |
throw new Error( | |
`All weights must be positive! ${item.original} has weight ${item.weight}` | |
); | |
} | |
if (set.has(item.original)) { | |
throw new Error(`Items must be unique! ${item.original} is duplicate!`); | |
} | |
set.add(item.original); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment