-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmentionCount.js
More file actions
59 lines (50 loc) · 1.48 KB
/
Copy pathmentionCount.js
File metadata and controls
59 lines (50 loc) · 1.48 KB
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
exports.count = function (data)
{
// response from API Call
var array = [];
var dataSet = data;
var dataSetLength = data.length;
for (var i = 0; i < dataSetLength; i++) {
var rics = data[i].PrimaryRics;
// Filter Articles without Ticker & Articles with Currency Ticker
if (rics != null && rics != undefined && rics.indexOf("=") == -1) {
if (rics.indexOf(" ") > -1) {
var result = rics.split(" ");
for (var j = 0; j < result.length; j++) {
if (hasTicker(array, result[j])) {
updateCount(array, result[j]);
} else {
addTicker(array, result[j]);
}
}
} else {
if (hasTicker(array, rics)) {
updateCount(array, rics);
} else {
addTicker(array, rics);
}
}
}
}
return array;
}
function addTicker(data, ticker){
data.push({
ticker: ticker,
mentions: 1
});
// tickersArray[tickersArray.length] = ticker;
}
function hasTicker(data, ticker) {
return data.some(function (el) {
return el.ticker === ticker;
});
}
function updateCount(data, ticker) {
for (var i=0; i < data.length; i++) {
if (data[i].ticker === ticker) {
data[i].mentions = data[i].mentions + 1;
return;
}
}
}