-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalgorithm21.html
More file actions
41 lines (27 loc) · 841 Bytes
/
algorithm21.html
File metadata and controls
41 lines (27 loc) · 841 Bytes
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
<!DOCTYPE html>
<html>
<body>
<script>
//https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris
//
const earthRadius = 6367.4447;
const GM = 398600.4418;
function calculatePeriod(alt) {
var orbitRadius = alt + earthRadius;
return Math.round(2*Math.PI*Math.sqrt(Math.pow(orbitRadius,3)/GM));
}
function transform (obj) {
var alt = obj.avgAlt;
delete obj.avgAlt;
obj.orbitalPeriod = calculatePeriod(alt);
return obj;
}
function orbitalPeriod(arr) {
return arr.map(transform);
}
//tests
console.log(orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]));
console.log(orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]));
</script>
</body>
</html>