Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/melkir/permutation-iterator
Iterate by permutation in a list using Heap's method
https://github.com/melkir/permutation-iterator
Last synced: 2 days ago
JSON representation
Iterate by permutation in a list using Heap's method
- Host: GitHub
- URL: https://github.com/melkir/permutation-iterator
- Owner: melkir
- License: mit
- Created: 2018-02-23T17:38:26.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-11-20T01:54:03.000Z (about 1 month ago)
- Last Synced: 2024-12-01T07:53:53.844Z (27 days ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# permutation-iterator [![Build Status](https://travis-ci.org/melkir/permutation-iterator.svg?branch=master)](https://travis-ci.org/melkir/permutation-iterator) [![codecov](https://codecov.io/gh/melkir/permutation-iterator/branch/master/graph/badge.svg)](https://codecov.io/gh/melkir/permutation-iterator)
> Iterate by permutations in a list
[![permutation][picture]](https://en.wikibooks.org/wiki/Probability/Combinatorics)
## Install
```
$ npm install permutation-iterator
```## Usage
### Array
```js
const permutationIterator = require('permutation-iterator');const it = permutationIterator(['a', 'b', 'c']);
it.next(); // => { value: ['a', 'b', 'c'], done: false }
it.next(); // => { value: ['b', 'a', 'c'], done: false }
it.next(); // => { value: ['c', 'a', 'b'], done: false }
it.next(); // => { value: ['a', 'c', 'b'], done: false }
it.next(); // => { value: ['b', 'c', 'a'], done: false }
it.next(); // => { value: ['c', 'b', 'a'], done: false }
it.next(); // => { value: undefined, done: true }
```### Object
```js
const it = permutationIterator({
1: 'a',
2: 'b',
3: 'c'
});// Same bahavior as arrays
it.next(); // => { value: ['a', 'b', 'c'], done: false }
```## License
MIT © Thibaut Vieux
[picture]: https://upload.wikimedia.org/wikipedia/commons/7/79/Permutation.png