
Security News
The Next Open Source Security Race: Triage at Machine Speed
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.
steinhaus-johnson-trotter
Advanced tools
Generate permutations using the Steinhaus-Johnson-Trotter algorithm.
A JavaScript implementation of the Steinhaus-Johnson-Trotter algorithm with Even's speedup to generate the permutations of a string or an array.
var permutations = require('steinhaus-johnson-trotter');
var generate = permutations("123");
console.log(generate()); // → '132'
console.log(generate()); // → '312'
console.log(generate()); // → '321'
console.log(generate()); // → '231'
console.log(generate()); // → '213'
console.log(generate()); // → undefined
permutations returns a function which returns another
permutation each time is is invoked. If all permutations
are generated it returns undefined. The source is never
included in the permutations returned, i.e. the number of
invocations that the generator returns a permutation is
N! - 1 where N is the length of the array/string.
All permutations can be generated as follows:
var sjt = require('steinhaus-johnson-trotter');
function permutations(arr) {
var generator = sjt(arr);
var next = arr;
var result = [];
while (next !== undefined) {
result.push(next);
next = generator();
}
return result;
}
The above function is also exported as all:
var permutations = require('steinhaus-johnson-trotter');
console.log(permutations.all([ 1, 4, 7 ]));
/* → [ [ 1, 4, 7 ],
[ 1, 7, 4 ],
[ 7, 1, 4 ],
[ 7, 4, 1 ],
[ 4, 7, 1 ],
[ 4, 1, 7 ] ] */
FAQs
Generate permutations using the Steinhaus-Johnson-Trotter algorithm.
We found that steinhaus-johnson-trotter 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.

Security News
Claude Opus 4.6 has uncovered more than 500 open source vulnerabilities, raising new considerations for disclosure, triage, and patching at scale.

Research
/Security News
Malicious dYdX client packages were published to npm and PyPI after a maintainer compromise, enabling wallet credential theft and remote code execution.

Security News
gem.coop is testing registry-level dependency cooldowns to limit exposure during the brief window when malicious gems are most likely to spread.