-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapTheDebris.js
42 lines (25 loc) · 1.22 KB
/
mapTheDebris.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
/*According to Kepler's Third Law, the orbital period T
of two point masses orbiting each other in a circular or elliptic orbit is:
T=2π√(a^3/μ)
a is the orbit's semi-major axis
μ=GM is the standard gravitational parameter
G is the gravitational constant,
M is the mass of the more massive body.
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
The values should be rounded to the nearest whole number. The body being orbited is Earth.
The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2. */
function orbitalPeriod(arr) {
const GM = 398600.4418;
const earthRadius = 6367.4447;
let arr2=[];
for(let i=0;i<arr.length;i++){
let a= earthRadius + arr[i].avgAlt;
let orbitalPeriod = Math.round(2*Math.PI*Math.sqrt(Math.pow(a,3)/GM));
arr2.push({name: arr[i].name, orbitalPeriod:orbitalPeriod});
}
console.log(arr2)
return arr2;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}])