-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
74 lines (60 loc) · 2.05 KB
/
utils.js
File metadata and controls
74 lines (60 loc) · 2.05 KB
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
let utils = {
getNextLaunchIndexFromAllLaunches: function(allLaunches) {
let nowTimestamp = Date.now();
let nextLaunchTimestamp = nowTimestamp + (100 * 365 * 24 * 60 * 60 * 1000);
let currentIndex = -1;
for (let i = 0; i < allLaunches.length; i++) {
let aLaunch = allLaunches[i];
let aLaunchTimestamp = aLaunch.date_unix * 1000;
if (
nowTimestamp < aLaunchTimestamp
&&
nextLaunchTimestamp > aLaunchTimestamp
) {
nextLaunchTimestamp = aLaunchTimestamp;
currentIndex = i;
}
}
return currentIndex;
},
getLaunchesPerMonthFromAllLaunches: function(allLaunches) {
let launchesPerMonth = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (let i = 0; i < allLaunches.length; i++) {
let aLaunch = allLaunches[i];
let dateUTC = aLaunch.date_utc;
let monthPart = dateUTC.split('-')[1];
let monthAsNumber = parseInt(monthPart);
launchesPerMonth[monthAsNumber - 1]++;
}
return launchesPerMonth;
},
getCrewMemberPhotoByCrewMemberId: function(allCrew, crewId) {
for (let i = 0; i < allCrew.length; i++) {
if (allCrew[i].id === crewId) {
return allCrew[i].image;
}
}
},
getCrewPrevCrewMember: function(allCrew, crewId) {
for (let i = 0; i < allCrew.length; i++) {
if (allCrew[i].id === crewId) {
if (i === 0) {
return null;
} else {
return allCrew[i - 1];
}
}
}
},
getCrewNextCrewMember: function(allCrew, crewId) {
for (let i = 0; i < allCrew.length; i++) {
if (allCrew[i].id === crewId) {
if (i === allCrew.length - 1) {
return null;
} else {
return allCrew[i + 1];
}
}
}
}
};