src/data.js   A
last analyzed

Complexity

Total Complexity 14
Complexity/F 2

Size

Lines of Code 94
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 14
c 1
b 0
f 0
nc 1
mnd 1
bc 15
fnc 7
dl 0
loc 94
rs 10
bpm 2.1427
cpm 2
noi 0

7 Functions

Rating   Name   Duplication   Size   Complexity  
A data.js ➔ list4 0 9 2
A data.js ➔ list5 0 9 2
A data.js ➔ list2 0 9 2
A data.js ➔ num8 0 3 1
B data.js ➔ list1 0 34 4
A data.js ➔ list3 0 14 2
A data.js ➔ indexers 0 8 1
1
import {TABLE1, TABLE2} from './constants';
2
3
export function list1(date) {
4
    // Last two digits of the year
5
    let year = parseInt(date.getFullYear().toString(10).substr(2, 2), 10);
6
7
    // Number of the month. The month in a Date object is zero-indexed,
8
    // i.e., January == 0, so we add 1 to satisfy the algorithm.
9
    let month = date.getMonth() + 1;
10
11
    let day_of_month = date.getDate();
12
13
    // Day of the week. Normally 0 would be Sunday but we need it to be Monday.
14
    let day_of_week = date.getDay() - 1;
15
    if (day_of_week < 0) {
16
        day_of_week = 6;
17
    }
18
19
    let list1 = [];
20
21
    for (let i = 0; i <= 4; i++) {
22
        list1[i] = TABLE1[day_of_week][i];
23
    }
24
25
    list1[5] = day_of_month;
26
27
    if (((year + month) - day_of_month) < 0) {
28
        list1[6] = (((year + month) - day_of_month) + 36) % 36;
29
    } else {
30
        list1[6] = ((year + month) - day_of_month) % 36;
31
    }
32
33
    list1[7] = (((3 + ((year + month) % 12)) * day_of_month) % 37) % 36;
34
35
    return list1;
36
}
37
38
export function list2(seed) {
39
    let list2 = [];
40
41
    for (let i = 0; i <= 7; i++) {
42
        list2[i] = (seed.charCodeAt(i)) % 36;
43
    }
44
45
    return list2;
46
}
47
48
export function num8(l3) {
49
    return l3[8] % 6;
50
}
51
52
export function list3(l1, l2) {
53
    let list3 = [];
54
55
    for (let i = 0; i <= 7; i++) {
56
        list3[i] = (((l1[i] + l2[i])) % 36);
57
    }
58
59
    list3[8] = (list3[0] + list3[1] + list3[2] + list3[3] + list3[4] +
60
        list3[5] + list3[6] + list3[7]) % 36;
61
62
    list3[9] = Math.round(Math.pow(num8(list3), 2));
63
64
    return list3;
65
}
66
67
export function list4(l3) {
68
    let list4 = [];
69
70
    for (let i = 0; i <= 9; i++) {
71
        list4[i] = l3[TABLE2[num8(l3)][i]];
72
    }
73
74
    return list4;
75
}
76
77
export function list5(seed, l4) {
78
    let list5 = [];
79
80
    for (let i = 0; i <= 9; i++) {
81
        list5[i] = (seed.charCodeAt(i) + l4[i]) % 36;
82
    }
83
84
    return list5;
85
}
86
87
export function indexers(date, seed) {
88
    let l1 = list1(date);
89
    let l2 = list2(seed);
90
    let l3 = list3(l1, l2);
91
    let l4 = list4(l3);
92
93
    return list5(seed, l4);
94
}
95