Map the Debris - Why does avgAlt need to be deleted?

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

I did this once with imperative(loop-based) programming, and later with ES6 higher-order functions, and apparently (looking at my old solutions), the first time, I understood the directions (reprinted here):

Return a new array that transforms the elements’ average altitude into their orbital periods (in seconds).

as saying - alter the elements themselves, and the second time, my thinking was as yours. In this toy problem, the “hint” solutions expend CPU cycles to save memory space. I can imagine that if you were in a near-Earth astronomy lab, operating on millions of asteroids and pieces of space junk, that it would be more economical to do so in RAM than to read/write from disk multiple times, and thus, directly modifying the objects themselves and creating a new array (of object references that point to the actual objects in RAM) would be required. But again, it’s a toy problem, so for scales like these, with dozen of elements, it doesn’t really matter.