historyarray
v1.1.1
Published
A type of array for storing states of history.
Downloads
2
Readme
A type of array for storing states of history.
Note that you are only expected to pull items out of history, never look at the 'current' one.
TypeScript definitions are included.
Usage
const { HistoryArray } = require("historyarray");
const SIZE = 5;
const OPTIONAL_INITIAL = "One";
const arr = new HistoryArray(SIZE, OPTIONAL_INITIAL);
arr.push("Two");
arr.push("Three");
arr.push("Four");
arr.push("Five");
arr.push("Six");
console.log(arr.forward()); // === null; nothing newer than the newest
console.log(arr.back()); // === "Five";
console.log(arr.forward()); // === "Six"; can go back and forth
arr.back(); arr.back();
arr.push("NewFive"); // kills history in front
console.log(arr.forward()); // === null;
arr.back(); arr.back();
console.log(arr.back()); // === "Two";
console.log(arr.back()); // === null; mustn't wrap around