Created
April 17, 2018 07:03
-
-
Save nickihastings/a1408bd515f7f486e1de2fd0d8b4223f to your computer and use it in GitHub Desktop.
Return a new array that transforms the element's average altitude into their orbital periods. The array will contain objects in the format {name: 'name', avgAlt: avgAlt}. You can read about orbital periods on wikipedia. The values should be rounded to the nearest whole number. The body being orbited is Earth. The radius of the earth is 6367.4447…
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) { | |
var GM = 398600.4418; | |
var earthRadius = 6367.4447; | |
//create a function to calculate orbital period | |
function calcPeriod(avgAlt){ | |
var orbitalRadius = earthRadius + avgAlt; | |
//calculation is 2 multiplied by pi multiplied by the square root of the | |
//orbital radius to the power of 3 divided by the GM | |
var period = Math.round(2*Math.PI*(Math.sqrt(Math.pow(orbitalRadius,3)/GM))); | |
return period; | |
} | |
//for every object in the array, work out the Orbital Period, add it to the | |
//object and remove the avgAlt entry. | |
arr.forEach(function(el){ | |
el.orbitalPeriod = calcPeriod(el.avgAlt); | |
delete el.avgAlt; | |
}); | |
return arr; | |
} | |
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment