
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
sliding-window-max
Advanced tools
[](https://chrvadala.github.io) [](https://github.com/chrvadala/sliding-window-max/actions) [![Coverage
Given a stream of data, this algorithm returns (for every added value) the current max value.
It uses a strategy that:
const SlidingWindowMax = require('sliding-window-max')
const windowSize = 3
const slidingWindowMax = new SlidingWindowMax(windowSize)
slidingWindowMax.add(0) // returns null
slidingWindowMax.add(5) // returns null
slidingWindowMax.add(10)// returns 10
slidingWindowMax.add(7) // returns 10
slidingWindowMax.add(8) // returns 10
slidingWindowMax.add(5) // returns 8
slidingWindowMax.add(3) // returns 8
slidingWindowMax.add(4) // returns 5
//etc ...
| VALUE | Max |
|---|---|
| [0] 5 10 7 8 5 3 4 | null |
| [0 5] 10 7 8 5 3 4 | null |
| [0 5 10] 7 8 5 3 4 | 10 |
| 0 [5 10 7] 8 5 3 4 | 10 |
| 0 5 [10 7 8] 5 3 4 | 10 |
| 0 5 10 [7 8 5] 3 4 | 8 |
| 0 5 10 7 [8 5 3] 4 | 8 |
| 0 5 10 7 8 [5 3 4] | 5 |
| ... | ... |
new SlidingWindowMax(windowSize, options)| Param | Default | Description |
|---|---|---|
| windowSize | required | Defines how many values should be considered to calculate the max |
| options.comparator | (a, b) => b - a | Override the custom comparator function |
| options.waitFullRange | true | If false the functions returns the max value also if the window size hasn't been reached yet |
add(value)Evaluate a new value and returns the calculated max value
I made this algorithm starting from this code https://github.com/chihungyu1116/leetcode-javascript/blob/master/239%20Sliding%20Window%20Maximum.js. My requirements were a bit different. The leetcode algorithm requires that all the data are known before it starts. With sliding-window-max you can:
FAQs
[](https://chrvadala.github.io) [](https://github.com/chrvadala/sliding-window-max/actions) [
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.