Help Requested for Map The Debris Challenge

Help Requested for Map The Debris Challenge
0

#1

Hello. I’m unable to clear the second step in the Map The Debris Challenge. I’ve added in a for-loop, 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}]);

#2

Never mind. Got it!..


#3

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}]);

#4

Your results formula is off just a bit. You got lucky with the first test case. A few helpful hints:

  1. Do not use round except on the final number.

  2. 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.

  3. Use Math.PI instead of 3.14

  4. 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.


#5

Thanks for the help. I was able to solve the problem.


#6

The formula is easier to understand within the following post:


#7

I already understand the formula.


#8

I know! You are the best! I mean the formula on wikipedia doesnt show the complete formula… Because a = h+r.