-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailExtraction.js
More file actions
39 lines (33 loc) · 1.36 KB
/
emailExtraction.js
File metadata and controls
39 lines (33 loc) · 1.36 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
const fs = require('fs');
const fileContents = fs.readFileSync('Emails.txt').toString();
const allEmailRegex = /@\S+\.\S+/g; //Regex to match all email addresses
const allEmailWithDifferentTopLevelDomain = /@\w+\.{1}/g; //Regex to match email address with same top level domain
const allEmailDomainMatches = fileContents.match(allEmailWithDifferentTopLevelDomain);
function readAndParseSoftWireEmails(emailLimit = 0) {
let dictEmails = {};
for (let i = 0; i < allEmailDomainMatches.length; i++) {
if (!dictEmails.hasOwnProperty(allEmailDomainMatches[i])) {
dictEmails[allEmailDomainMatches[i]] = 1;
}
else {
dictEmails[allEmailDomainMatches[i]]++;
}
}
let sortedValues = Object.entries(dictEmails).sort((a, b) => b[1] - a[1]);
//Printing first 10 highest occurences
console.log('Printing top 10 occurences of email domains')
for (let j = 0; j <= 10; j++) {
console.log(sortedValues[j]);
}
//Printing occurences greater than provided limit
if (emailLimit != 0) {
console.log('Printing email domains greater than provided count')
for (let j = 0; j < sortedValues.length; j++) {
if (sortedValues[j][1] > emailLimit) {
console.log(sortedValues[j]);
}
}
}
}
const userInput = 100;
readAndParseSoftWireEmails(userInput);