
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
array-permutation
Advanced tools
permutation utils. Return Iterable
for iterating all permutations of an array.
var permutation = require('array-permutation');
var range = permutation.range;
var random = permutation.random;
var shuffle = permutation.shuffle;
Return [0,..,n-1]
Return [low, low + step, low + 2 * step,..., low + k * step], with low + k * step < high
Return an array populated with a random permutation of range(n)
Return an array populated with a random permutation of range(low, high, step)
Return an iterable, for iterating all permutations of range(n)
Return an iterable, for iterating all permutations of range(low, high, step)
Return an iterable, for iterating all permutations of the given array.
Shuffle the given array, and return it.
var perm = require('..');
var iter = perm([1, 2, 3, 4]);
for (var p of iter) {
console.log(p);
}
output:
ā node example/permutation.js
[ 1, 2, 3, 4 ]
[ 2, 1, 3, 4 ]
[ 2, 3, 1, 4 ]
[ 2, 3, 4, 1 ]
[ 1, 3, 2, 4 ]
[ 3, 1, 2, 4 ]
[ 3, 2, 1, 4 ]
[ 3, 2, 4, 1 ]
[ 1, 3, 4, 2 ]
[ 3, 1, 4, 2 ]
[ 3, 4, 1, 2 ]
[ 3, 4, 2, 1 ]
[ 1, 2, 4, 3 ]
[ 2, 1, 4, 3 ]
[ 2, 4, 1, 3 ]
[ 2, 4, 3, 1 ]
[ 1, 4, 2, 3 ]
[ 4, 1, 2, 3 ]
[ 4, 2, 1, 3 ]
[ 4, 2, 3, 1 ]
[ 1, 4, 3, 2 ]
[ 4, 1, 3, 2 ]
[ 4, 3, 1, 2 ]
[ 4, 3, 2, 1 ]
var random = require('..').random;
console.log(random(5)); // [ 3, 2, 4, 1, 0 ]
console.log(random(2, 5)); // [ 4, 3, 2 ]
console.log(random(1, 5, 2)); // [ 3, 1 ]
console.log(random([1, 2, 3, 4, 5])); // [ 4, 5, 3, 1, 2 ]
output:
ā node example/random.js
[ 4, 0, 1, 2, 3 ]
[ 4, 2, 3 ]
[ 3, 1 ]
[ 3, 4, 1, 5, 2 ]
FAQs
permutation utils
The npm package array-permutation receives a total of 569 weekly downloads. As such, array-permutation popularity was classified as not popular.
We found that array-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.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600Ć faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.