Created
June 1, 2017 04:42
-
-
Save khalid32/e881a71689269c74e53269f3aba5dad7 to your computer and use it in GitHub Desktop.
Freecodecamp's Advanced Algorithm Scripting Challenge
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; | |
arr.forEach(function(obj){ | |
var orbPeriod = Math.round(2*Math.PI*Math.sqrt(Math.pow(earthRadius + obj.avgAlt, 3)/GM)); | |
obj.orbitalPeriod = orbPeriod; | |
delete obj.avgAlt; | |
}); | |
return arr; | |
} | |
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); |
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; | |
return arr.reduce(function(acc, obj){ | |
var orbPeriod = Math.round(2*Math.PI*Math.sqrt(Math.pow(earthRadius + obj.avgAlt, 3)/GM)); | |
acc.push({name: obj.name, orbitalPeriod: orbPeriod}); | |
return acc; | |
}, []); | |
} | |
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment