offenders = {
const groups = {};
const regex = /^https?:\/\/([^/?#]+)(?:[/?#]|$)/i;
for (let i = 0, len = all_data.length; i < len; i++) {
const link = all_data[i];
if (['https:/', 'http://'].includes(link.href)) continue
const hostname = regex.exec(link.href)[1];
if (hostname in groups) {
groups[hostname] = [...groups[hostname], link.status_class];
} else {
groups[hostname] = [link.status_class];
}
}
const topLinked = Object.keys(groups)
.reduce((acc, key) => {
const count = groups[key].length;
return [
...acc,
[key, count]
];
}, [])
.sort((a, b) => b[1] - a[1]);
const sortedBySuccess = Object.keys(groups)
.reduce((acc, key) => {
const count = groups[key].length;
const successCount = groups[key].filter(code => code === "SUCCESS").length;
const successRatio = successCount / count;
if (count >= 10) {
return [
...acc,
[key, successRatio]
]
}
return acc;
}, [])
.sort((a, b) => a[1] - b[1]);
return sortedBySuccess;
}