|
3 | 3 |
|
4 | 4 | [](https://nodei.co/npm/percom/) |
5 | 5 |
|
6 | | -npm package listing and calculating combination and permutation |
| 6 | +Utility for listing and counting combinations and permutations. |
7 | 7 |
|
8 | | -# Usage |
| 8 | +# Install |
9 | 9 |
|
10 | 10 | ``` |
11 | 11 | $ npm i percom |
12 | 12 | ``` |
13 | 13 |
|
14 | | - ## 1. Listing every possible combinatioins (組み合わせ) |
15 | | - ```JavaScript |
16 | | - import percom from "percom"; |
17 | | - |
18 | | - percom.com(array,num); |
19 | | - //array => Target array (対象の配列) |
20 | | - //num => Number of elements in a combination (組み合わせの数) |
21 | | - ``` |
22 | | - #### Example |
23 | | - ```JavaScript |
24 | | - const array = ["A","B","C"]; |
25 | | - |
26 | | - const result1 = percom.com(array, 2); |
27 | | - //result1 = [ [ "A", "B" ], [ "A, "C ], [ "B", "C" ] ] |
28 | | - |
29 | | - const result2 = percom.com(array, 1); |
30 | | - //result2 = [ [ "A" ], [ "B" ], [ "C" ] ] |
31 | | - ``` |
32 | | - |
33 | | - ### Count the number of possible combination (組み合わせの数を数える) |
34 | | - ```JavaScript |
35 | | - percom.countCom(n, r); |
36 | | - //n => Number of elements in an array (要素数) |
37 | | - //r => Number of elements in a combination (選ぶ要素の数) |
38 | | - ``` |
39 | | - #### Example |
40 | | - ```JavaScript |
41 | | - percom.countCom(8, 3); |
42 | | - // => 56 |
43 | | - ``` |
44 | | - |
45 | | - ## 2. Listing every possible permutaiton (順列) |
46 | | - ```JavaScript |
47 | | - percom.per(array,num); |
48 | | - //array => Target array (対象の配列) |
49 | | - //num => Number of elements in a permutation (一つ一つの順列の要素数) |
50 | | - ``` |
51 | | - |
52 | | - #### Example |
53 | | - ```JavaScript |
54 | | - const array = ["A","B","C"]; |
55 | | - |
56 | | - const result1 = percom.per(array, 2); |
57 | | - //result1 = [ [ 'A', 'B' ], [ 'A', 'C' ], [ 'B', 'A' ], [ 'B', 'C' ], [ 'C', 'A' ], [ 'C', 'B' ] ] |
58 | | - |
59 | | - const result2 = percom.per(array, 1); |
60 | | - //result2 = [ [ "A" ], [ "B" ], [ "C" ] ] |
61 | | - ``` |
62 | | - ### Count the number of possible permutation (順列の数を数える) |
63 | | - ```JavaScript |
64 | | - percom.countPer(n, r); |
65 | | - //n => Number of elements in an array (要素数) |
66 | | - //r => Number of elements in a permutation (一つ一つの順列の要素数) |
67 | | - ``` |
68 | | - #### Example |
69 | | - ```JavaScript |
70 | | - percom.countPer(8, 3); |
71 | | - // => 336 |
72 | | - ``` |
| 14 | +# Usage |
| 15 | + |
| 16 | +## 1. List all combinations |
| 17 | + |
| 18 | +```javascript |
| 19 | +import percom from "percom"; |
| 20 | + |
| 21 | +percom.com(array, r); |
| 22 | +// array: source array |
| 23 | +// r: size of each combination |
| 24 | +``` |
| 25 | + |
| 26 | +Example |
| 27 | + |
| 28 | +```javascript |
| 29 | +const array = ["A", "B", "C"]; |
| 30 | + |
| 31 | +const result1 = percom.com(array, 2); |
| 32 | +// result1 = [["A", "B"], ["A", "C"], ["B", "C"]] |
| 33 | + |
| 34 | +const result2 = percom.com(array, 1); |
| 35 | +// result2 = [["A"], ["B"], ["C"]] |
| 36 | +``` |
| 37 | + |
| 38 | +### Count combinations |
| 39 | + |
| 40 | +```javascript |
| 41 | +percom.countCom(n, r); |
| 42 | +// n: number of elements |
| 43 | +// r: size of each combination |
| 44 | +``` |
| 45 | + |
| 46 | +Example |
| 47 | + |
| 48 | +```javascript |
| 49 | +percom.countCom(8, 3); // => 56 |
| 50 | +``` |
| 51 | + |
| 52 | +## 2. List all permutations |
| 53 | + |
| 54 | +```javascript |
| 55 | +percom.per(array, r); |
| 56 | +// array: source array |
| 57 | +// r: size of each permutation |
| 58 | +``` |
| 59 | + |
| 60 | +Example |
| 61 | + |
| 62 | +```javascript |
| 63 | +const array = ["A", "B", "C"]; |
| 64 | + |
| 65 | +const result1 = percom.per(array, 2); |
| 66 | +// result1 = [["A", "B"], ["A", "C"], ["B", "A"], ["B", "C"], ["C", "A"], ["C", "B"]] |
| 67 | + |
| 68 | +const result2 = percom.per(array, 1); |
| 69 | +// result2 = [["A"], ["B"], ["C"]] |
| 70 | +``` |
| 71 | + |
| 72 | +### Count permutations |
| 73 | + |
| 74 | +```javascript |
| 75 | +percom.countPer(n, r); |
| 76 | +// n: number of elements |
| 77 | +// r: size of each permutation |
| 78 | +``` |
| 79 | + |
| 80 | +Example |
| 81 | + |
| 82 | +```javascript |
| 83 | +percom.countPer(8, 3); // => 336 |
| 84 | +``` |
73 | 85 |
|
74 | 86 | # License |
75 | | - percom is under [MIT license](https://opensource.org/licenses/mit-license.php) |
| 87 | +percom is available under the [MIT License](https://opensource.org/licenses/mit-license.php). |
76 | 88 |
|
77 | 89 | # Development |
78 | 90 | ```javascript |
79 | 91 | yarn install |
80 | 92 |
|
81 | | -// before create PR |
| 93 | +// before creating a PR |
82 | 94 | yarn mocha |
83 | 95 | ``` |
84 | 96 | Since lint-staged and husky are set up, your code will be formatted before commit. |
85 | 97 |
|
86 | 98 | # Developer |
87 | | - Kota Yatagai (https://kota_yata.com) |
| 99 | +Kota Yatagai (https://kota_yata.com) |
0 commit comments