Reference · Rolls and exact odds
addToHistoryfunction
Add a roll to the end, oldest dropped past the limit. Returns a new array.
Import it
import { addToHistory } from "@johnmorrisdotca/korokoro";
Definition
function addToHistory(history: readonly Roll[], roll: Roll, limit?: number): Roll[]
Parameters
| Name | Type | Description |
|---|---|---|
history | readonly Roll[] | Completed rolls, newest first where the history API requires it. |
roll | Roll | The completed roll to read or record. |
limit (optional) | number | The maximum number of records retained. |
Returns
Roll[]
Add a roll to the end, oldest dropped past the limit. Returns a new array.
Examples
import { addToHistory } from "@johnmorrisdotca/korokoro";
import { normalizeSpec, rollFrom } from "@johnmorrisdotca/korokoro";
const spec = normalizeSpec({ count: 2, sides: 6 });
const sample = rollFrom(spec, [2, 5], "saved", 0, null)!;
console.log(addToHistory([], sample).length);1What it prints (run when this page was built)