1 | import { equalityComparer } from '../util/comparer';
|
2 | import { identity } from '../util/identity';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export function min(source, options) {
|
13 | const { ['comparer']: comparer = equalityComparer, ['selector']: selector = identity } = options || {};
|
14 | const it = source[Symbol.iterator]();
|
15 | let next = it.next();
|
16 | if (next.done) {
|
17 | throw new Error('Sequence contains no elements');
|
18 | }
|
19 | let minValue = selector(next.value);
|
20 | while (!(next = it.next()).done) {
|
21 | const current = selector(next.value);
|
22 | if (comparer(current, minValue) < 0) {
|
23 | minValue = current;
|
24 | }
|
25 | }
|
26 | return minValue;
|
27 | }
|
28 |
|
29 |
|