Simple minimal implementation of a container that keeps up a specified difference between the newest and oldest elements.
If the time difference between the added element and the oldest elements is bigger than the specified one, the oldest elements are deleted.
npm install temporary-container --save
const {TemporaryContainer} = require("temporary-container");
let collect = new TemporaryContainer(5*1000); //5 seconds
setInterval( () => {
let dataItem = new Date().toString();
let timestamp = new Date().getTime();
collect.put(dataItem, timestamp);
console.log(collect.toArray());
}, 1000);
Type: number|Long
The maximum milliseconds between the oldest and the newest value.
Put the item with timestampMs
unix timestamp in milliseconds value.
Type: any
The item to put.
Type: number|Long|Date
The timestamp of the item to put.
Convert a TemporaryContainer
into array of container elements without a timestamps.
Returns an Array
of container elements.
Any ideas, as well as refactoring and comments on improving the code are welcome.
Make tests
- 0.1.0 Initial release
ISC © Yevhen Stohniienko