1 | Lists all possible permutations.
|
2 | [:package:](https://www.npmjs.com/package/@extra-array/permutations)
|
3 | [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array)
|
4 | [:running:](https://npm.runkit.com/@extra-array/permutations)
|
5 | [:vhs:](https://asciinema.org/a/332961)
|
6 | [:moon:](https://www.npmjs.com/package/@extra-array/permutations.min)
|
7 | [:scroll:](https://unpkg.com/@extra-array/permutations/)
|
8 | [:newspaper:](https://nodef.github.io/extra-array/)
|
9 | [:blue_book:](https://github.com/nodef/extra-array/wiki/)
|
10 |
|
11 | > Similar: [permutation], [permutations], [hasPermutation].
|
12 |
|
13 | > This is part of package [extra-array].
|
14 |
|
15 | [extra-array]: https://www.npmjs.com/package/extra-array
|
16 |
|
17 | <br>
|
18 |
|
19 | ```javascript
|
20 | array.permutations(x, [n]);
|
21 | // x: an array
|
22 | // n: number of values (-1 => any)
|
23 | ```
|
24 |
|
25 | ```javascript
|
26 | const array = require("extra-array");
|
27 |
|
28 | [...array.permutations([1, 2])];
|
29 | // [ [], [ 1 ], [ 2 ], [ 1, 2 ], [ 2, 1 ] ]
|
30 |
|
31 | [...array.permutations([1, 2, 3])];
|
32 | // [
|
33 | // [], [ 1 ],
|
34 | // [ 2 ], [ 3 ],
|
35 | // [ 1, 2 ], [ 1, 3 ],
|
36 | // [ 2, 1 ], [ 2, 3 ],
|
37 | // [ 3, 1 ], [ 3, 2 ],
|
38 | // [ 1, 2, 3 ], [ 1, 3, 2 ],
|
39 | // [ 2, 1, 3 ], [ 2, 3, 1 ],
|
40 | // [ 3, 1, 2 ], [ 3, 2, 1 ]
|
41 | // ]
|
42 |
|
43 | [...array.permutations([1, 2, 3], 2)];
|
44 | // [ [ 1, 2 ], [ 1, 3 ], [ 2, 1 ], [ 2, 3 ], [ 3, 1 ], [ 3, 2 ] ]
|
45 | ```
|
46 |
|
47 | <br>
|
48 | <br>
|
49 |
|
50 |
|
51 | ## References
|
52 |
|
53 | - [Data.List.permutations: Haskell](https://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:permutations)
|
54 |
|
55 | [permutation]: https://github.com/nodef/extra-array/wiki/permutation
|
56 | [permutations]: https://github.com/nodef/extra-array/wiki/permutations
|
57 | [hasPermutation]: https://github.com/nodef/extra-array/wiki/hasPermutation
|