Tell us what’s happening:
I went through the solutions here, and all delete the avgAlt
property from the array, and add a new property orbitalPeriod
.
Why is this done, when we could just make a new object instead with the name and orbitalPeriod as it’s keys? Is there any advantage to deleting one key and adding in another?
Your code so far
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
const PI = Math.PI;
var calculatedArr = [];
function calculatePeriod(avgAlt){
console.log("calculating - Orbital period="+Math.round(2*PI*Math.sqrt(Math.pow(avgAlt+earthRadius,3)/GM)));
return Math.round(2*PI*Math.sqrt(Math.pow(avgAlt+earthRadius,3)/GM));
}
arr.forEach(function(element){
console.log("Running: "+element.name);
calculatedArr.push({
"name": element.name,
"orbitalPeriod": calculatePeriod(element.avgAlt)
});
});
return calculatedArr;
}
console.log(orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris