Function circularArray

Returns a new circular array. Immutable. A circular array only keeps up to capacity items. Old items are overridden with new items.

CircularArray extends the regular JS array. Only use add to change the array if you want to keep the CircularArray behaviour.

let a = circularArray(10);
a = a.add(`hello`); // Because it's immutable, capture the return result of `add`
a.isFull; // True if circular array is full
a.pointer; // The current position in array it will write to

Since it extends the regular JS array, you can access items as usual:

let a = circularArray(10);
... add some stuff ..
a.forEach(item => // do something with item);
  • Type Parameters

    • V

    Parameters

    • capacity: number

      Maximum capacity before recycling array entries

    Returns CircularArray<V>

    Circular array