-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreport.js
More file actions
31 lines (29 loc) · 937 Bytes
/
report.js
File metadata and controls
31 lines (29 loc) · 937 Bytes
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
// printReport takes a dictionary of pages and prints them
// to the console in a human-friendly way
function printReport(pages) {
console.log('==========')
console.log('REPORT')
console.log('==========')
const sortedPages = sortPages(pages)
for (const sortedPage of sortedPages) {
const url = sortedPage[0]
const count = sortedPage[1]
console.log(`Found ${count} internal links to ${url}`)
}
}
// 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) => {
if (pageB[1] === pageA[1]) {
return pageA[0].localeCompare(pageB[0])
}
return pageB[1] - pageA[1]
})
return pagesArr
}
export { printReport, sortPages }