Hello. I’m unable to clear the second step in the Map The Debris Challenge. I’ve added in a forloop, which doesn’t seem to fix the problem. Could somebody offer some pointers? Thanks!
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
var newArray = [];
for (var i = 0; i < arr.length; i++) {
var results = (Math.round((Math.round(2*3.14*(Math.sqrt(Math.pow((earthRadius + arr[i].avgAlt), 3)/GM))))/100))*100;
newArray.push({
name: arr[i].name,
orbitalPeriod: results
});
}
return newArray;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
So, I thought I had it, but I guess not. I thought using reduce would take care of the problem.
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
return arr.reduce(function(acc, obj){
var results = (Math.round((Math.round(2*3.14*(Math.sqrt(Math.pow((earthRadius + arr[0].avgAlt), 3)/GM))))/100))*100;
acc.push({name: obj.name, orbitalPeriod: results});
return acc;
}, []);
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
Your results formula is off just a bit. You got lucky with the first test case. A few helpful hints:

Do not use round except on the final number.

There is no reason to use arr[0].avgAlt. arr[0] would be the same element during each iteration of the reduce. Use obj.avgAlt instead, because obj represents each element (object) being iterated over with reduce.

Use Math.PI instead of 3.14

Not sure why you are dividing and multiplying by 100 in your formula. That is not part of the formula found on the Wikipedia site.
Thanks for the help. I was able to solve the problem.
The formula is easier to understand within the following post:
I already understand the formula.
I know! You are the best! I mean the formula on wikipedia doesnt show the complete formula… Because a = h+r.
I used map function and I solved the issue ,despite of not understanding the mathematical task .