Skip to content

JS library to calculate and list permutation and combination. No dependencies

License

Notifications You must be signed in to change notification settings

kota-yata/Percom

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

98 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Percom

npm version Build Status License: MIT

NPM

Utility for listing and counting combinations and permutations.

Install

$ npm i percom

Usage

1. List all combinations

import percom from "percom";

percom.com(array, r);
// array: source array
// r: size of each combination

Example

const array = ["A", "B", "C"];

const result1 = percom.com(array, 2);
// result1 = [["A", "B"], ["A", "C"], ["B", "C"]]

const result2 = percom.com(array, 1);
// result2 = [["A"], ["B"], ["C"]]

Count combinations

percom.countCom(n, r);
// n: number of elements
// r: size of each combination

Example

percom.countCom(8, 3); // => 56

2. List all permutations

percom.per(array, r);
// array: source array
// r: size of each permutation

Example

const array = ["A", "B", "C"];

const result1 = percom.per(array, 2);
// result1 = [["A", "B"], ["A", "C"], ["B", "A"], ["B", "C"], ["C", "A"], ["C", "B"]]

const result2 = percom.per(array, 1);
// result2 = [["A"], ["B"], ["C"]]

Count permutations

percom.countPer(n, r);
// n: number of elements
// r: size of each permutation

Example

percom.countPer(8, 3); // => 336

License

percom is available under the MIT License.

Development

yarn install

// before creating a PR
yarn mocha

Since lint-staged and husky are set up, your code will be formatted before commit.

Developer

Kota Yatagai (https://kota_yata.com)

About

JS library to calculate and list permutation and combination. No dependencies

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •