Last active
July 14, 2019 09:26
-
-
Save Luckerella/711f7d0ccfdedfff65a1f63701368dfe to your computer and use it in GitHub Desktop.
[Map The Debris] 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 th…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function orbitalPeriod(arr) { | |
const GM = 398600.4418; | |
const earthRadius = 6367.4447; | |
for (let i = 0; i < arr.length; i++) { | |
const height = Math.round(arr[i].avgAlt); | |
const r = Math.round(earthRadius + height); | |
const r3 = Math.round(Math.pow(r, 3)); | |
const pi = 2 * Math.PI; | |
const T = Math.round(pi * Math.sqrt(r3 / GM)); | |
delete arr[i].avgAlt; | |
arr[i].orbitalPeriod = T; | |
} | |
return arr; | |
} | |
console.log(orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}])); | |
// returns | |
// [ { name: 'iss', orbitalPeriod: 5557 }, | |
// { name: 'hubble', orbitalPeriod: 5734 }, | |
// { name: 'moon', orbitalPeriod: 2377399 } ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment