permutils
v1.0.1
Published
Utility package for permutations, including Lehmer codes.
Downloads
3
Maintainers
Readme
permutils
Utility package for permutations, including Lehmer codes.
Example
var permutils = require('permutils');
/* .swap and .shuffle are useful permutation utilities */
var array = ["a", "b", "c"];
permutils.swap(array, 0, 1); // array is now ["b", "a", "c"]
permutils.shuffle(array); // Fisher–Yates shuffle, array is randomly ordered
/* Use .factoriadic and .unfactoriadic to encode/decode permutations as/from integers */
array = [2, 1, 0];
permutils.factoriadic(array); // -> 5
permutils.unfactoriadic(5, 3); // -> [2, 1, 0]
/* Apply permutations */
array = ["a", "b", "c"];
permutils.permute(array, [0, 1, 2]); // array is untouched
permutils.permute(array, [2, 1, 0]); // array is reversed
Testing
npm run test
npm run test-coverage
Currently, permutils has 100% code coverage.