
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
iterative-permutation
Advanced tools
Fast, iterative implementation of Heap's Algorithm for JavaScript
This is a non-recursive implementation of Heap's Algorithm that can be used to generate permutations for very large sets of values. Typically recursive solutions generate all sets of values and then return them all at the end. For very large sets it becomes problematic to store all of the permutations in memory. Instead this implementation returns permutations one at a time so they can be processed and discarded if needed.
npm install iterative-permutation
var Permutation = require('iterative-permutation');
var generator = new Permutation([1, 2, 3]);
while (generator.hasNext()) {
console.log(generator.next());
}
console.log('finished');
Prints:
[ 1, 2, 3 ]
[ 2, 1, 3 ]
[ 3, 1, 2 ]
[ 1, 3, 2 ]
[ 2, 3, 1 ]
[ 3, 2, 1 ]
finished
This implementation keeps track of the algorithm stack in a variable called
stack and then updates it with the current index each time a new permutation
is calculated. It only uses for loops and simple function calls and has no
external dependencies, just regular ol' JavaScript. Why no ES6 generators? Some
people have found that generators are a
little slow
and typically when you need a large number of permutations it's in a hot code
path. This implementation tries to be as fast as reasonably possible.
Brian Card: @bmcard
MIT License - Copyright 2015 Brian Card
FAQs
Fast, iterative implementation of Heap's Algorithm
We found that iterative-permutation demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.