1.0.2 • Published 6 years ago

@magic8bot/fixedset v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

FixedSet

Is identical to a plain Javascript ES6 Set but with a cap on it's size. Once x amount of items have been added to the set it will start dropping the first item in the set.

Usage

Syntax

new Set(setSize: number, ...items: T[])`

Example

import { FixedSet } from '@magic8bot/fixedset'

const fixedSet = new FixedSet(5, [1, 2, 3, 4]) // Set [1, 2, 3, 4]
fixedSet.add(5) // Set [1, 2, 3, 4, 5]
fixedSet.add(6) // Set [2, 3, 4, 5, 6]
fixedSet.add(7) // Set [3, 4, 5, 6, 7]