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