forked from Laboratoria/DEV010-md-links
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.js
52 lines (44 loc) · 1.24 KB
/
stats.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
const brokenLinks = (statsLinksArray) => {
let brokenCounter = 0;
statsLinksArray.map((statusLink) => {
if(statusLink.ok === 'fail') {
brokenCounter ++;
}
})
return brokenCounter;
}
const totalLinks = (statsLinksArray) => {
let linksCounter = 0;
statsLinksArray.map((statusLink) => {
if(statusLink.href) {
linksCounter++;
}
})
return linksCounter;
}
const uniqueLinks = (statsLinksArray) => {
const uniqueLinksArray = [];
statsLinksArray.map((statusLink) => {
if(!uniqueLinksArray.includes(statusLink.href)) {
uniqueLinksArray.push(statusLink.href);
}
})
return uniqueLinksArray.length;
}
const simpleStats = (statsLinksArray) => {
const total = totalLinks(statsLinksArray);
const unique = uniqueLinks(statsLinksArray);
return `Total: ${total}\nUnique: ${unique}`;
}
const statsValidate = (statsLinksArray) => {
const total = totalLinks(statsLinksArray);
const unique = uniqueLinks(statsLinksArray);
const broken = brokenLinks(statsLinksArray);
return `Total: ${total}\nUnique: ${unique}\nBroken: ${broken}`;
}
module.exports = {
simpleStats,
statsValidate,
brokenLinks,
totalLinks,
};