sliding-score-window
v2.3.5
Published
Fixed-size sliding window with ordered min/max tracking, built on btree-core.
Downloads
22,160
Maintainers
Readme
sliding-score-window
Fixed-size sliding window with ordered min/max tracking, built on btree-core.
Install
npm install sliding-score-windowUsage
const SlidingScoreWindow = require('sliding-score-window');
const win = new SlidingScoreWindow(3);
win.push(10);
win.push(20);
win.push(5);
win.min(); // 5
win.max(); // 20
win.sum; // 35
win.push(40); // evicts 10
win.values(); // [20, 5, 40]API
| Method / prop | Description |
| --- | --- |
| push(score) | Add score; may evict oldest |
| min() | Current minimum |
| max() | Current maximum |
| values() | Scores oldest → newest |
| clear() | Reset window |
| size | Current count |
| capacity | Max size |
| sum | Sum of scores |
| average | Mean of scores |
License
MIT
