Skip to content

melkir/permutation-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

permutation-iterator Build Status codecov

Iterate by permutations in a list

permutation

Install

$ npm install permutation-iterator

Usage

Array

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

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

About

Iterate by permutation in a list using Heap's method

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published