Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/josepot/id-permutations
https://github.com/josepot/id-permutations
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/josepot/id-permutations
- Owner: josepot
- Created: 2018-12-09T14:18:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T01:58:58.000Z (almost 2 years ago)
- Last Synced: 2024-10-31T06:02:46.607Z (8 days ago)
- Language: JavaScript
- Size: 485 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# id-permutations
Blazing fast algorithms for generating a list of permutations for a given id,
or the id from its corresponding permutation.## Example
```js
const N_POSITIONS = 10;
const {
getPermutationsFromId,
getIdFromPermutations,
} = require('id-permutations')(N_POSITIONS);getPermutationsFromId(0); // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
getPermutationsFromId(1); // => [1, 0, 2, 3, 4, 5, 6, 7, 8, 9]
getPermutationsFromId(2); // => [2, 0, 1, 3, 4, 5, 6, 7, 8, 9]
getPermutationsFromId(3628799); // => [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]getIdFromPermutations([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); // => 0
getIdFromPermutations([1, 0, 2, 3, 4, 5, 6, 7, 8, 9]); // => 1
getIdFromPermutations([2, 0, 1, 3, 4, 5, 6, 7, 8, 9]); // => 2
getIdFromPermutations([9, 8, 7, 6, 5, 4, 3, 2, 1, 0]); // => 3628799
```