Skip to content

Instantly share code, notes, and snippets.

@clive-bunting
Created December 8, 2015 20:39
Show Gist options
  • Select an option

  • Save clive-bunting/82711ee792655223bedd to your computer and use it in GitHub Desktop.

Select an option

Save clive-bunting/82711ee792655223bedd to your computer and use it in GitHub Desktop.
Bonfire: Map the Debris
// Bonfire: Map the Debris
// Author: @clive-bunting
// Challenge: http://www.freecodecamp.com/challenges/bonfire-map-the-debris
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
var results = [];
for(var i = 0; i < arr.length; i++) {
var semiMajorAxis = earthRadius + arr[i].avgAlt;
var T = Math.round( 2.0 * Math.PI * Math.sqrt( Math.pow(semiMajorAxis, 3) / GM ));
results.push({name: arr[i].name, orbitalPeriod: T});
}
return results;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment