-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
53 lines (46 loc) · 1.25 KB
/
report.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
// printReport takes a dictionary of pages and prints them
// to the console in a human-friendly way
function printpages(pages){
console.log('==========')
console.log('REPORT')
console.log('==========')
const sortedPages = sortPages(pages)
const sortedarr=Object.keys(sortedPages)
for (const sortedelement of sortedarr){
const url = sortedelement
const count = sortedPages[sortedelement].count
const brokenurls=sortedPages[sortedelement].brokenurls
console.log(`Found ${count} internal links to ${url}`)
if(brokenurls.length!==0){
console.log("Broken urls on this page are")
console.log(brokenurls)
}
}
}
// sortPages sorts a dictionary of pages
// into a list of tuples (url, count)
// with the highest counts first in the list
/*function sortPages(pages){
// 2D array where the
// inner array: [ url, count ]
const pagesArr = Object.entries(pages)
pagesArr.sort((pageA, pageB) => {
return pageB[1] - pageA[1]
})
return pagesArr
}
*/
function sortPages(pages){
const sortedarr={}
const arr=Object.keys(pages).sort((p1,p2)=>{
return pages[p2].count-pages[p1].count
})
arr.forEach((key)=>{
sortedarr[key]=pages[key]
})
return sortedarr
}
module.exports = {
printpages,
sortPages,
}