- 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
function smartAssigning(information) {
var bestAvailability;
var currentPerson;
// greedy O(n) algorithm to find best availability
for(var i=0; i<information.length; i++){
currentPerson = information[i];
// ensure not on vacation
if(currentPerson[1]==1){
// set best if not set yet
if(!bestAvailability){
bestAvailability = currentPerson;
}
// if equal tasks
else if(bestAvailability[3]==currentPerson[3]){
// check if current person has fewer projects
if(currentPerson[2] < bestAvailability[2]){
bestAvailability = currentPerson;
}
}
// if not equal tasks
else if(bestAvailability[3]!=currentPerson[3]){
// check if current person has fewer tasks
if(currentPerson[3] < bestAvailability[3]){
bestAvailability = currentPerson;
}
}
}
}
return bestAvailability[0];
}