Forked from anonymous/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%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%3B%20i%2B%2B)%20%7B%0A%20%2
Last active
November 24, 2015 23:54
-
-
Save wallyatkins/1a54b6f487b09a7ab3c5 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dfu23 's solution for Bonfire: Map the Debris
This file contains hidden or 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 | |
| // Author: @dfu23 | |
| // Challenge: 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%20%0A%20%20for%20(var%20i%20%3D%200%3B%20i%20%3C%20arr.length%3B%20i%2B%2B)%20%7B%0A%20%20%20%20var%20answer%20%3D%20(Math.PI%20*%202)%20*%20Math.sqrt(Math.pow(earthRadius%20%2B%20arr%5Bi%5D.avgAlt%2C%203)%20%2F%20GM)%3B%0A%20%20%20%20delete%20arr%5Bi%5D.avgAlt%3B%0A%20%20%20%20arr%5Bi%5D.orbitalPeriod%20%3D%20Math.round(answer)%3B%0A%20%20%7D%0A%20%20%0A%20%20return%20arr%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; | |
| for (var i = 0; i < arr.length; i++) { | |
| var answer = (Math.PI * 2) * Math.sqrt(Math.pow(earthRadius + arr[i].avgAlt, 3) / GM); | |
| delete arr[i].avgAlt; | |
| arr[i].orbitalPeriod = Math.round(answer); | |
| } | |
| 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