-
Notifications
You must be signed in to change notification settings - Fork 0
/
algorithm.js
63 lines (54 loc) · 1.39 KB
/
algorithm.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var want = new Array(input.length).fill(false);
var keywords = [{"text": "\\?", "after": 3}];
byContent(input, keywords);
var trange = 5000;
byFrequency(input);
minLength = 128;
byLength(input);
minReactions = 3;
byReactions(input);
// final output
for (let i = 0; i < input.length; i ++) {
if (want[i]) {
console.log(input[i]);
}
}
function byContent(a, b) {
for (let t = 0; t < b.length; t ++) {
for (let i = 0; i < a.length; i ++) {
if (a[i].text.search(b[t].text) != -1) {
for (let j = 0; j <= b[t].after; j ++) {
want[i + j] = true;
}
}
}
}
}
function byFrequency(a) {
for (let i = 1; i < a.length; i ++) {
if ((a[i].ts - a[i - 1].ts) <= trange) {
want[i] = true;
want[i - 1] = true;
}
}
}
function byLength(a) {
for (let i = 0; i < a.length; i ++) {
if (a[i].length >= minLength) {
want[i] = true;
}
}
}
function byReactions(a) {
for (let i = 0; i < a.length; i ++) {
a[i].reactioncount = 0;
if (a[i].reactions != undefined) {
for (let j = 0; j < a[i].reactions.length; j ++) {
a[i].reactioncount += a[i].reactions[j].count;
}
if (a[i].reactioncount >= minReactions) {
want[i] = true;
}
}
}
}