Skip to content

Commit

Permalink
1 file edited
Browse files Browse the repository at this point in the history
  • Loading branch information
Croc-Prog-github authored Jun 18, 2024
1 parent 9bb5c58 commit 83d8571
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,22 @@

addObject(instanceName, listName, object, probability) {
if (!this.instances[instanceName] || !this.instances[instanceName][listName]) {
throw new Error("List or instance does not exist");
throw new Error(`List or instance does not exist. Instance: ${instanceName}, List: ${listName}`);
}

const list = this.instances[instanceName][listName];
list.objects.push({ object, probability });
list.totalWeight += probability;

// Verifica che la somma delle probabilità sia 100
// Verifica che la somma delle probabilità non superi 100
if (list.totalWeight > 100) {
throw new Error("The sum of the probabilities is greater than 100%");
} else if (list.totalWeight < 100) {
throw new Error("The sum of the probabilities is less than 100%");
throw new Error(`The sum of the probabilities is greater than 100%. Instance: ${instanceName}, List: ${listName}`);
}
}

getRandomObject(instanceName, listName) {
if (!this.instances[instanceName] || !this.instances[instanceName][listName]) {
throw new Error("List or instance does not exist");
throw new Error(`List or instance does not exist. Instance: ${instanceName}, List: ${listName}`);
}

const list = this.instances[instanceName][listName];
Expand All @@ -140,11 +138,15 @@
}
random -= probability;
}

throw new Error(`Failed to get random object. Instance: ${instanceName}, List: ${listName}`);
}

clearInstance(instanceName) {
if (this.instances[instanceName]) {
delete this.instances[instanceName];
} else {
throw new Error(`Instance does not exist. Instance: ${instanceName}`);
}
}

Expand Down

0 comments on commit 83d8571

Please sign in to comment.