expFunction.ts 1.13 KB
Newer Older
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
29
30
31
32
33
34
35
36
37
import { AllExperimentList, SortInfo } from '../../static/interface';
import { copyAndSort } from '../../static/function';

function compareDate(date1: Date, date2: Date): boolean {
    if (date1 !== undefined && date2 !== undefined) {
        if (date1.getFullYear() === date2.getFullYear()) {
            if (date1.getMonth() === date2.getMonth()) {
                if (date1.getDate() === date2.getDate()) {
                    return true;
                }
            }
        }
    }

    return false;
}

const filterByStatusOrPlatform = (val: string, type: string, data: AllExperimentList[]): AllExperimentList[] => {
    return data.filter(temp => temp[type] === val);
};

function fillOptions(arr: string[]): any {
    const list: Array<object> = [];

    arr.map(item => {
        list.push({ key: item, text: item });
    });

    return list;
}

function getSortedSource(source: AllExperimentList[], sortInfo: SortInfo): AllExperimentList[] {
    const keepSortedSource = copyAndSort(source, sortInfo.field, sortInfo.isDescend);
    return keepSortedSource;
}

export { compareDate, filterByStatusOrPlatform, fillOptions, getSortedSource };