Map the Debris not passing

Map the Debris not passing
0

#1

Tell us what’s happening:

Your code so far


function orbitalPeriod(arr) {
  // console.log(arr);
  var GM = 398600.4418;
  var earthRadius = 6367.4447;

  arr.forEach(function(arr) {
    Object.defineProperties(arr, {
      orbitalPeriod: {
        value: Math.round(2 * Math.PI * Math.sqrt(Math.pow(earthRadius + arr.avgAlt, 3) / GM))
      }
    })
    delete arr.avgAlt;
  })


  return arr;
}


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

It returns the array as expected but the test still not passing it.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/map-the-debris


#2

You have to return a new array. Not change the existing one. .map would therefore be better than .forEach


#3

Here is my code but I failed passing the test as well:
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;

return Arr=arr.map(val=>(`{name: "${val.name}", orbitalPeriod: ${Math.round(Math.sqrt(4*Math.pow(Math.PI,2)*Math.pow(val.avgAlt+earthRadius,3)/GM))})}`)); }
console.log(orbitalPeriod([{name : “sputnik”, avgAlt : 35873.5553}]));
console.log(orbitalPeriod([{name: “iss”, avgAlt: 413.6}, {name: “hubble”, avgAlt: 556.7}, {name: “moon”, avgAlt: 378632.553}]));
here are the Chrome result:
["{name: “sputnik”, orbitalPeriod: 86400)}"]

(3) ["{name: “iss”, orbitalPeriod: 5557)}", “{name: “hubble”, orbitalPeriod: 5734)}”, “{name: “moon”, orbitalPeriod: 2377399)}”]
0
:
“{name: “iss”, orbitalPeriod: 5557)}”
1
:
“{name: “hubble”, orbitalPeriod: 5734)}”
2
:
“{name: “moon”, orbitalPeriod: 2377399)}”