-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
32 lines (25 loc) · 666 Bytes
/
index.js
File metadata and controls
32 lines (25 loc) · 666 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
32
const gender = require('gender');
const fs = require('fs');
fetchNames = () => {
return fs.readFileSync('names.txt').toString().split('\n');
}
const names = fetchNames();
genders = () => {
let female = 0;
let male = 0;
names.forEach(name => {
if (gender.guess(name).gender === 'male') {
male++;
} else if (gender.guess(name).gender === 'female') {
female++;
} else {
return;
}
})
const total = female + male;
const fPercent = ((female / total) * 100).toFixed(2);
const mPercent = ((male / total) * 100).toFixed(2);
console.log('female: ', fPercent, '%');
console.log('male: ', mPercent, '%');
}
genders();