2.4 KiB
id, title, challengeType, forumTopicId, dashedName
| id | title | challengeType | forumTopicId | dashedName |
|---|---|---|---|---|
| af4afb223120f7348cdfc9fd | Мапа Debris | 1 | 16021 | map-the-debris |
--description--
Згідно з третім законом Кеплера, орбітальний період T двох точкових мас, що обертаються навколо одна одної по круговій або еліптичній орбіті, є:
T = 2 \pi \sqrt{\frac{a^{3}}{\mu}}
ais the orbit's semi-major axisμ = GMis the standard gravitational parameterGis the gravitational constant,Mis the mass of the more massive body.
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
The values should be rounded to the nearest whole number. The body being orbited is Earth.
The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2.
--hints--
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]) повинен повертати [{name: "sputnik", orbitalPeriod: 86400}].
assert.deepEqual(orbitalPeriod([{ name: 'sputnik', avgAlt: 35873.5553 }]), [
{ name: 'sputnik', orbitalPeriod: 86400 }
]);
orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]) повинен повертати [{name : "iss", orbitalPeriod: 5557}, {name: "hubble", orbitalPeriod: 5734}, {name: "moon", orbitalPeriod: 2377399}].
assert.deepEqual(
orbitalPeriod([
{ name: 'iss', avgAlt: 413.6 },
{ name: 'hubble', avgAlt: 556.7 },
{ name: 'moon', avgAlt: 378632.553 }
]),
[
{ name: 'iss', orbitalPeriod: 5557 },
{ name: 'hubble', orbitalPeriod: 5734 },
{ name: 'moon', orbitalPeriod: 2377399 }
]
);
--seed--
--seed-contents--
function orbitalPeriod(arr) {
const GM = 398600.4418;
const earthRadius = 6367.4447;
return arr;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
--solutions--
function orbitalPeriod(arr) {
const GM = 398600.4418;
const earthRadius = 6367.4447;
const TAU = 2 * Math.PI;
return arr.map(function(obj) {
return {
name: obj.name,
orbitalPeriod: Math.round(TAU * Math.sqrt(Math.pow(obj.avgAlt+earthRadius, 3)/GM))
};
});
}