1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const last = set => {
|
14 | let last;
|
15 | for (const item of set) last = item;
|
16 | return last;
|
17 | };
|
18 |
|
19 | /**
|
20 | * @template T
|
21 | * @param {Iterable<T>} iterable iterable
|
22 | * @param {function(T): boolean} filter predicate
|
23 | * @returns {boolean} true, if some items match the filter predicate
|
24 | */
|
25 | const someInIterable = (iterable, filter) => {
|
26 | for (const item of iterable) {
|
27 | if (filter(item)) return true;
|
28 | }
|
29 | return false;
|
30 | };
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | const countIterable = iterable => {
|
38 | let i = 0;
|
39 |
|
40 | for (const _ of iterable) i++;
|
41 | return i;
|
42 | };
|
43 |
|
44 | exports.last = last;
|
45 | exports.someInIterable = someInIterable;
|
46 | exports.countIterable = countIterable;
|