-
Notifications
You must be signed in to change notification settings - Fork 2
/
min.ts
28 lines (19 loc) · 753 Bytes
/
min.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { IIterator } from "../intefaces/iterator.interface";
import { SelectClause } from "./select";
import { BaseIterator } from "../implements/baseIterator";
export class MinClause<T> extends BaseIterator<T> implements IIterator<T> {
_iterator: (item: T) => any;
execute(source: T[]): number {
if (!source) return 0;
let _result;
if(this._iterator)
_result = new SelectClause(this._iterator).execute(source) as number[];
if (!_result) return 0;
if (!Number.isNaN(_result[0])) throw new Error("Min operator require type of number");
return Math.min(..._result);
}
constructor(func?: (item: T) => any) {
super();
this._iterator = func;
}
}