Created
January 15, 2016 11:44
-
-
Save SerhiiLihus/9dd658053f4fc7f327ba to your computer and use it in GitHub Desktop.
Return a new array that transforms the element's average altitude into their orbital periods.
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
// Bonfire: Map the Debris(Upper Intermediate Algorithm) | |
// Author: @serhiilihus | |
// http://www.freecodecamp.com/challenges/bonfire-map-the-debris#?solution=function%20orbitalPeriod(arr)%20%7B%0A%20%20var%20GM%20%3D%20398600.4418%3B%0A%20%20var%20earthRadius%20%3D%206367.4447%3B%0A%20%20var%20newArr%20%3D%20%5B%5D%2C%20period%3B%0A%20%20arr.forEach(function(value)%7B%0A%20%20%20period%20%3D%20Math.round(2*Math.PI*Math.sqrt(Math.pow(value.avgAlt%20%2B%20earthRadius%2C3)%2FGM))%3B%0A%20%20%20newArr.push(%7Bname%20%3A%20value.name%2C%20orbitalPeriod%20%3A%20period%7D)%3B%0A%20%20%7D)%3B%0A%20%20return%20newArr%3B%0A%7D%0A%0AorbitalPeriod(%5B%7Bname%20%3A%20%22sputnik%22%2C%20avgAlt%20%3A%2035873.5553%7D%5D)%3B%0A | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function orbitalPeriod(arr) { | |
var GM = 398600.4418; | |
var earthRadius = 6367.4447; | |
var newArr = [], period; | |
arr.forEach(function(value){ | |
period = Math.round(2*Math.PI*Math.sqrt(Math.pow(value.avgAlt + earthRadius,3)/GM)); | |
newArr.push({name : value.name, orbitalPeriod : period}); | |
}); | |
return newArr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment