Skip to content

Commit 79ea9c5

Browse files
1 file added, 3 file edited
1 parent 3c9c5db commit 79ea9c5

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

.github/Releases/v1.0.1.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Probability-Manager.js - v1.0.1
2+
La versione: v1.0.1 è stata rilasciata il -/-/-.
3+
Le Distribuzioni precedenti sono disponibili nella sezione [Release di GitHub](https://github.com/Croc-Prog-github/Probability-Manager.js/tags).
4+
5+
## Modifiche
6+
Aggiunte le funzioni:
7+
- toArray()
8+
- toArrayForInstance(instanceName)
9+
10+
Esempio di utilizzo:
11+
```JS
12+
const var1 = probManager.toArrayForInstance('Instance1');
13+
let var2 = probManager.toArray();
14+
console.log(var1, var2);
15+
```

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Una semplice libreria per JS che semplifica la gestione della probabilità, sopr
2727

2828
## Utilizzo
2929
Per utilizzare la libreria segui i passaggi sottostanti.
30-
1. Scarica il file in base al linguaggio principale che utilizzi: [JavaScript](https://github.com/Croc-Prog-github/Probability-Manager.js/blob/main/core/Probability-Manager.js) oppure [TypeScript](https://github.com/Croc-Prog-github/Probability-Manager.js/blob/main/core/Probability-Manager.ts)
30+
1. Scarica il file libreria (dall'ultimo Relase stabile) in base al linguaggio che utilizzi: [JavaScript](https://github.com/Croc-Prog-github/Probability-Manager.js/blob/v1.0.0/core/Probability-Manager.js) oppure [TypeScript](https://github.com/Croc-Prog-github/Probability-Manager.js/blob/v1.0.0/core/Probability-Manager.ts)
3131
2. Sposta il file nella directory del tuo progetto.
3232
3. In un altro file Js o Ts, inserisci in alto la stringa: `const probManager = new ProbabilityManager();` per dichiarare l'utilizzo della libreria.
3333
4. Inizia a scrivere codice, usando i comandi illustrati appena sotto.
@@ -70,4 +70,11 @@ Rimuove tutte le liste e gli oggetti associati a una specifica istanza.<br>
7070
- **instanceName** Il nome dell'istanza da rimuovere.
7171

7272
**`probManager.clearAll()`**
73-
Rimuove tutte le istanze, insieme a tutte le liste e gli oggetti associati.
73+
Rimuove tutte le istanze, insieme a tutte le liste e gli oggetti associati.
74+
75+
**`probManager.toArray()`**
76+
...
77+
78+
**`probManager.toArrayForInstance(instanceName)`**
79+
...
80+
- **instanceName**: ...

core/example.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@ probManager.addObject('Instance1', '1', 'Bronze coin', 50);
1212
let randomEvent = probManager.getRandomObject('Instance1', '1');
1313
console.log(`Extracted object: `+ randomEvent);
1414

15+
const arrayRepresentation = probManager.toArrayForInstance('Instance1');
16+
console.log(arrayRepresentation);
17+
1518
// Cleanup of instances
1619
probManager.clearInstance('Instance1');

docs/index.html

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919

2020
// Creation of instances and lists
2121
probManager.addList('Instance1', '1');
22-
22+
2323
// Adding objects with probability
2424
probManager.addObject('Instance1', '1', 'Gold coin', 15);
2525
probManager.addObject('Instance1', '1', 'Silver coin', 35);
2626
probManager.addObject('Instance1', '1', 'Bronze coin', 50);
27-
27+
2828
// Extraction of a random object
2929
let randomEvent = probManager.getRandomObject('Instance1', '1');
3030
console.log(`Extracted object: `+ randomEvent);
31-
31+
32+
const arrayRepresentation = probManager.toArrayForInstance('Instance1');
33+
console.log(arrayRepresentation);
34+
3235
// Cleanup of instances
3336
probManager.clearInstance('Instance1');</textarea>
3437
<textarea name="Output" id="Out" rows="7" disabled style="resize: none;">Edit the example for run it: add an Enter or a Space.</textarea>
@@ -176,5 +179,19 @@
176179
}
177180
return result;
178181
}
182+
183+
toArrayForInstance(instanceName) {
184+
const result = [];
185+
const lists = this.instances[instanceName];
186+
if (!lists) {
187+
throw new Error(`Instance does not exist. Instance: ${instanceName}`);
188+
}
189+
for (const [listName, list] of Object.entries(lists)) {
190+
for (const { object, probability } of list.objects) {
191+
result.push([instanceName, listName, object, probability]);
192+
}
193+
}
194+
return result;
195+
}
179196
}
180197
</script>

0 commit comments

Comments
 (0)