/
matching_algorithm.js
52 lines (47 loc) · 1.73 KB
/
matching_algorithm.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
const projects = require('./mock_projects.js');
// given a project object (see mock_projects.js) and a list of
// consultant objects (see mock_consultants.js), filter the list
// of consultants down to a list that are qualified to be assigned
// to the project, and return the list
function filterConsultantsForProject (project, consultants){
// TODO: actually implement this. return all consultants for now
console.log(project);
console.log(consultants);
switch(project.priority) {
case projects.PRIORITIES.LOCATION:
console.log(project.location);
consultants = consultants.filter(consultant => consultant.locations.includes(project.locations[0]));
break;
case projects.PRIORITIES.BUDGET:
consultants = consultants.sort((a, b) => {
return a.pay_amount - b.pay_amount;
});
break;
case projects.PRIORITIES.QUALITY:
consultants = consultants.sort((a, b) => {
return b.avg_rating - a.avg_rating;
});
break;
case projects.PRIORITIES.EXPERIENCE:
consultants = consultants.sort((a, b) => {
return b.prev_jobs.length - a.prev_jobs.length;
});
break;
}
return consultants
}
// given a project object (see mock_projects.js) and a list of
// consultant objects (see mock_consultants.js), rank the list
// of consultants based on most qualified to least, and
// return the list
function rankConsultantsForProject (project, consultants){
// TODO: actually implement this. return all consultants for now
return consultants
}
module.exports = {
getConsultants: function (project, consultants) {
filtered = filterConsultantsForProject(project, consultants)
ranked = rankConsultantsForProject(project, filtered)
return ranked
}
}