percom
Version:
A calculation npm module that is to simplify the calculation of permutations and combinations
94 lines (73 loc) • 2.63 kB
Markdown
# Percom
[](https://badge.fury.io/js/percom) [](https://travis-ci.org/kota-yata/Percom) [](https://opensource.org/licenses/MIT)
[](https://nodei.co/npm/percom/)
Combination and Permutation library
# Usage
```
$ npm i percom
```
## 1. Combinatioins (組み合わせ)
```JavaScript
const percom = require("percom");
percom.com(array,num);
//array => Target array (対象の配列)
//num => Number to combine as combinations (組み合わせの数)
```
#### Example
```JavaScript
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 the number of combination elements (組み合わせの数を数える)
```JavaScript
percom.countCom(n, r);
//n => Number of elements : int (要素数)
//r => Number to choose : int (選ぶ要素の数)
```
#### Example
```JavaScript
percom.countCom(8, 3);
// => 56
```
## 2. Permutations (順列)
```JavaScript
percom.per(array,num);
//array => Target array (対象の配列)
//num => Number to combine as permutations (一つ一つの順列の要素数)
```
#### Example
```JavaScript
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 the number of permutation elements (順列の数を数える)
```JavaScript
percom.countPer(n, r);
//n => Number of elements : int (要素数)
//r => Number to choose : int (選ぶ要素の数)
```
#### Example
```JavaScript
percom.countPer(8, 3);
// => 336
```
# Test Coverage

Both uncovered lines are returning of recursive function
# License
percom is under [MIT license](https://opensource.org/licenses/mit-license.php)
# Development
```javascript
yarn install
// before create PR
yarn mocha
```
Since lint-staged and husky are set up, your code will be formatted before commit.
# Developer
Kota Yatagai (https://twitter.com/kota_yata)