-
Notifications
You must be signed in to change notification settings - Fork 0
/
career-guesser.js
37 lines (34 loc) · 1.2 KB
/
career-guesser.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
import { cleanString } from './utils'
import * as careerWords from './career-words'
function careerMatches(career, words) {
return words.some(word => career.indexOf(word) !== -1)
}
export function guessCareer(careerString) {
const career = cleanString(careerString.toLowerCase())
// Careers are tested in order
if (careerMatches(career, careerWords.politician)) {
return 'politician'
} else if (careerMatches(career, careerWords.executive)) {
return 'executive'
} else if (careerMatches(career, careerWords.civilService)) {
return 'civil_service'
} else if (careerMatches(career, careerWords.whiteCollar)) {
return 'white_collar'
} else if (careerMatches(career, careerWords.barrister)) {
return 'barrister'
} else if (careerMatches(career, careerWords.teacher)) {
return 'teacher'
} else if (careerMatches(career, careerWords.journalist)) {
return 'journalist'
} else if (careerMatches(career, careerWords.athlete)) {
return 'athlete'
} else if (careerMatches(career, careerWords.manualWorker)) {
return 'manual_worker'
} else {
if (career.length !== 0) {
console.log('Unable to find career for:')
console.log(career)
}
return 'unknown'
}
}