-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
114 lines (98 loc) · 3.44 KB
/
script.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
/*
Gets the top 5 matches to a person
Parameters:
origin - string
destination - string
age - number
doNotDisturb - boolean
family - boolean
firstClass - boolean
seatLocation - number
interests - boolean[5]
Returns:
Array of 5 Person
*/
function getMatches(origin, destination, age, doNotDisturb, family, firstClass, seatLocation, interests){
// function sends in a flight number and recies back a person array *Jennifer
var people_on_flight = people_arr;
var output = new Array(5);
var compareScores = [0, 0, 0, 0, 0];
for (index = 0; index < people_on_flight.length; index++) {
var compareScore = 0;
var tempPerson = people_on_flight[index];
// If both are same class, +2000 to compatibility score (don't want peasants mixing with the rich)
if(firstClass == tempPerson.firstClass) {
compareScore += 2000;
}
// If age is within 10 years of other person, +50 to compatibility score
var minAge = tempPerson.age - 5;
var maxAge = tempPerson.age + 5;
if(age > minAge && age < maxAge) {
compareScore += 50;
}
// If they both don't want to be disturbed, +300 to compatibility score
if(doNotDisturb == tempPerson.doNotDisturb) {
compareScore += 300;
}
// If both have families, +30 to compatibility score
if(family == tempPerson.family) {
compareScore += 30;
}
// If both want to sit in different seats, +15 to compatibility score
if(seatLocation != tempPerson.seatLocation) {
compareScore += 25;
}
// For every shared interest, +20 to compatibility score
for(x = 0; x < interests.length; x++) {
if(interests[x] && tempPerson.interests[x]) {
compareScore += 50;
}
}
// Checks if in the top 5, if so, then kicks lowest one out
inTopFive = false;
count = 0;
while(!inTopFive && count < compareScores.length) {
if(compareScore > compareScores[count]) { // Found, kick out lowest
inTopFive = true;
smallestIndex = 0;
smallestCompareScore = 10000;
for(x = 0; x < compareScores.length; x++) {
if(compareScores[x] < smallestCompareScore) {
smallestIndex = x;
smallestCompareScore = compareScores[x];
}
}
compareScores[smallestIndex] = compareScore;
output[smallestIndex] = tempPerson;
}
count++;
}
}
for(var i = 0 ; i < 5 ; i++){
console.log(output[i].name);
}
return output;
};
function get_flight_num(origin, dest){
// Flight numbers generated from FlightEngineAPI
var flight_num = [1755, 2288, 4699, 2641, 3782, 5977, 3191, 8168, 7855, 4416, 4669, 7977, 3515, 683, 9806, 8609];
var org_num;
var dest_num;
if(origin == "JFK")
org_num = 0;
else if (origin == "DFW")
org_num = 1;
else if (origin == "LAX")
org_num = 2;
else
org_num = 3;
if(dest == "JFK")
dest_num = 0;
else if (dest == "DFW")
dest_num = 1;
else if (dest == "LAX")
dest_num = 2;
else
dest_num = 3;
return flight_num[org_num * 4 + dest_num];
};