Skip to content

egoist/string-permutation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

string-permutation NPM version NPM downloads Build Status

Find all permutations of a string by a given length.

Install

$ npm install --save string-permutation

Usage

const permutation = require('string-permutation')

permutation('ab', 2)
//=> ['aa', 'ab', 'ba', 'bb']

permutation('ab', {maxSize: 2, recursive: true})
//=> ['a', 'b', 'aa', 'ab', 'ba', 'bb']

const alphabet = 'abcdefghijklmnopqrstuvwxyz'
permutation(alphabet, 2)
/**
[
  'aa',
  'ab',
  'ac',
  ...
  'zx',
  'zy',
  'zz'
]
*/

API

stringPermutation(input, [options])

input

Type: string

The allowed characters.

options

Type: number object

When it's a number we treat it as the options.maxSize

maxSize

Type: number

The size of each item in the result.

recursive

Type: boolean
Default: false

Including the items whose length is smaller than maxSize.

License

MIT © EGOIST

About

Find all permutations of a string by a given length.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published