-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·117 lines (106 loc) · 2.43 KB
/
index.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const readline = require('readline')
const clone = require('clone')
const {stripIndents} = require('common-tags')
const persons = require('./persons')
const questions = [
{
id: 'gender',
q: 'What is the gender of the patient?',
},
{
id: 'darkHair',
q: 'Does the patient have dark hair?',
},
{
id: 'earlobe',
q: 'Is the patient\'s earlobe attached?',
},
{
id: 'allTeeth',
q: 'Does the patient still have all regular teeth?',
},
{
id: 'handFoldConnected',
q: 'Are the patient\'s hand folds connected?',
},
{
id: 'wisdomTeeth',
q: 'Does the patient have wisdom teeth?',
},
{
id: 'toothFilling',
q: 'Does the patient have tooth fillings?',
},
{
id: 'bothFeet',
q: 'Does the patient have both feet?',
},
{
id: 'bothArms',
q: 'Does the patient have both arms?',
},
{
id: 'allFingers',
q: 'Does the patient have all fingers?',
},
{
id: 'handForm',
q: 'Which hand form does the patient have?',
},
{
id: 'allToes',
q: 'Does the patient have all toes?',
},
{
id: 'footShape',
q: 'Which foot shape does the patient have?',
},
{
id: 'tall',
q: 'Is the patient tall? (larger than 1.60 m)',
},
{
id: 'earHole',
q: 'Does the patient have an ear hole, ear holes?',
},
]
module.exports = (id) => {
let candidates = clone(persons)
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})
function questionLoop (index) {
question = questions[index].q + ' '
rl.question(question, answer => {
answer = answer.toLowerCase()
if (['y', 'yes', 'true'].includes(answer)) answer = true
if (['n', 'no', 'false'].includes(answer)) answer = false
questions[index].a = answer
candidates = candidates.filter(candidate =>
candidate[questions[index].id] === answer
)
if (!candidates.length) {
console.error('No match!')
process.exit(1)
}
if (candidates.length > 1) {
questionLoop(++index)
}
else {
const candidate = candidates[0]
rl.close()
const sep = '\n================\n'
console.info('\n')
console.info(stripIndents `
${sep}
${candidate.name}
Emergency Contact: ${candidate.emergencyContact}
Organ Donor: ${candidate.organDonor}
${sep}
`)
}
})
}
questionLoop(0)
}