JavaScript Orbital Period

Requirements

Implementation

orbitalPeriod(arr) calculates the orbital period of ojects around the Earth in seconds. Input array arr is an array of objects in the format: { name: 'name', avgAlt: avgAlt } where avgAlt is the object's average altitude in kilometers. Returns an array of objects in the format: { name: 'name', orbitalPeriod: T } where T is the orbital period in seconds.

Similarly orbitalPeriodHours(arr) calculates the orbital period around the Earth in hours, and orbitalPeriodDays(arr) calculates the orbital period in days.

Example Usage

Use the browser console to interact with the function (Ctrl + Shift + I, then select the "Console" tab):

> orbitalPeriod([{ name : "sputnik", avgAlt : 35873.5553 }]);
// Returns: [{ name: 'sputnik', orbitalPeriod: 86400 }]

> orbitalPeriodHours([{ name : "sputnik", avgAlt : 35873.5553 }]);
// Returns: [{ name: 'sputnik', orbitalPeriodHours: 24 }]

> orbitalPeriodDays([{ name: "moon", avgAlt: 378632.553 }]);
// Returns: [{ name: 'moon', orbitalPeriodDays: 28 }]