1 | import { flatten } from '../../utils/array.js';
|
2 | import { factory } from '../../utils/factory.js';
|
3 | var name = 'setSize';
|
4 | var dependencies = ['typed', 'compareNatural'];
|
5 | export var createSetSize = factory(name, dependencies, (_ref) => {
|
6 | var {
|
7 | typed,
|
8 | compareNatural
|
9 | } = _ref;
|
10 |
|
11 | |
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | return typed(name, {
|
33 | 'Array | Matrix': function ArrayMatrix(a) {
|
34 | return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
|
35 | },
|
36 | 'Array | Matrix, boolean': function ArrayMatrixBoolean(a, unique) {
|
37 | if (unique === false || a.length === 0) {
|
38 | return Array.isArray(a) ? flatten(a).length : flatten(a.toArray()).length;
|
39 | } else {
|
40 | var b = flatten(Array.isArray(a) ? a : a.toArray()).sort(compareNatural);
|
41 | var count = 1;
|
42 |
|
43 | for (var i = 1; i < b.length; i++) {
|
44 | if (compareNatural(b[i], b[i - 1]) !== 0) {
|
45 | count++;
|
46 | }
|
47 | }
|
48 |
|
49 | return count;
|
50 | }
|
51 | }
|
52 | });
|
53 | }); |
\ | No newline at end of file |