Map the Debris code return NaN

Tell us what’s happening:
I’m trying to solve Map the Derbis Algorithm challenge
I’m trying to insert the new property orbitalPeriod to the newObject through for loop
but when I run code return is
=> [ { name: ‘iss’, orbitalPeriod: NaN },
{ name: ‘hubble’, orbitalPeriod: NaN },
{ name: ‘moon’, orbitalPeriod: NaN } ]
what is wrong with my code why I get orbitalPeriod: NaN???

Your code so far

function orbitalPeriod(arr) {
  var GM = 398600.4418;
  var earthRadius = 6367.4447;
  var newObject = arr;
  //console.log(Math.floor(2* Math.PI * Math.sqrt(Math.pow(arr[0].avgAlt + earthRadius, 3)/ GM)));

  for(var i = 0; i < arr.length; i++){

    delete newObject[i].avgAlt;    
    newObject[i].orbitalPeriod = Math.floor(2* Math.PI * Math.sqrt(Math.pow(arr[i].avgAlt + earthRadius, 3)/ GM));
   return newObject;

orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36.

Link to the challenge:

var newObject = arr;
When you do this, newObject and arr are actually references to the same object. That means that when you delete avgAlt from newObject[i] you then can’t use arr[i].avgAlt.

1 Like