showing results for - "freecodecap map the debris"
Alex
19 May 2019
1const orbitalPeriod = arr => {
2  const GM = 398600.4418;
3  const earthRadius = 6367.4447;
4  const root = 2 * Math.PI
5
6  const orbitalPeriods = arr.map(elem => {
7    let avgAlt = elem.avgAlt // avgAlt from current looped object
8    delete elem.avgAlt // Delete avgAlt from the object
9    const numerator = (earthRadius + avgAlt)**3 // Power of 3 or power of x(**x)
10    const innerRoot = Math.sqrt(numerator / GM) // Square root
11    const orbitalPeriod = Math.ceil(innerRoot * root); // Round a number upward to its nearest integer
12    
13    // Since we are using map, we return a new object of all the initial elements and the new one
14    return {
15      ...elem,
16      orbitalPeriod
17    }
18
19  })
20
21  return orbitalPeriods
22}
23
24orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]);
25
26// With love @kouqhar