Files
.circleci
.github
api-server
client
config
curriculum
challenges
english
01-responsive-web-design
02-javascript-algorithms-and-data-structures
basic-algorithm-scripting
basic-data-structures
basic-javascript
debugging
es6
functional-programming
intermediate-algorithm-scripting
arguments-optional.english.md
binary-agents.english.md
convert-html-entities.english.md
diff-two-arrays.english.md
dna-pairing.english.md
drop-it.english.md
everything-be-true.english.md
make-a-person.english.md
map-the-debris.english.md
meta.json
missing-letters.english.md
pig-latin.english.md
search-and-replace.english.md
seek-and-destroy.english.md
smallest-common-multiple.english.md
sorted-union.english.md
spinal-tap-case.english.md
steamroller.english.md
sum-all-numbers-in-a-range.english.md
sum-all-odd-fibonacci-numbers.english.md
sum-all-primes.english.md
wherefore-art-thou.english.md
javascript-algorithms-and-data-structures-projects
object-oriented-programming
regular-expressions
03-front-end-libraries
04-data-visualization
06-information-security-and-quality-assurance
08-coding-interview-prep
09-certificates
docs
formattingConversion
math-challenges
requiresTests
schema
.babelrc
.editorconfig
.eslintignore
.eslintrc
.npmignore
.prettierrc
.travis.yml
CHANGELOG.md
LICENSE.md
README.md
addAssertsToTapTest.js
challengeTitles.js
commitizen.config.js
commitlint.config.js
create-challenge-bundle.js
getChallenges.js
gulpfile.js
index.js
lib.js
md-conversion.js
mongoIds.js
package-entry.js
package-lock.json
package.json
repack.js
test-challenges.js
unpack.js
unpacked.css
unpacked.js
unpackedChallenge.js
utils.js
docs
news
tools
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.node-inspectorrc
.prettierrc
.snyk
.travis.yml
.vcmrc
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE.md
README.md
docker-compose-shared.yml
docker-compose.yml
lerna.json
netlify.toml
package-lock.json
package.json
sample.env

79 lines
2.8 KiB
Markdown
Raw Normal View History

---
id: af4afb223120f7348cdfc9fd
title: Map the Debris
challengeType: 5
---
## Description
<section id='description'>
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
The array will contain objects in the format <code>{name: 'name', avgAlt: avgAlt}</code>.
You can read about orbital periods <a href="http://en.wikipedia.org/wiki/Orbital_period" target='_blank'>on Wikipedia</a>.
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 km<sup>3</sup>s<sup>-2</sup>.
Remember to use <a href='http://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck/19514' target='_blank'>Read-Search-Ask</a> if you get stuck. Try to pair program. Write your own code.
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}])</code> should return <code>[{name: "sputnik", orbitalPeriod: 86400}]</code>.'
testString: 'assert.deepEqual(orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]), [{name: "sputnik", orbitalPeriod: 86400}], "<code>orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}])</code> should return <code>[{name: "sputnik", orbitalPeriod: 86400}]</code>.");'
- text: '<code>orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}])</code> should return <code>[{name : "iss", orbitalPeriod: 5557}, {name: "hubble", orbitalPeriod: 5734}, {name: "moon", orbitalPeriod: 2377399}]</code>.'
testString: '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}], "<code>orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}])</code> should return <code>[{name : "iss", orbitalPeriod: 5557}, {name: "hubble", orbitalPeriod: 5734}, {name: "moon", orbitalPeriod: 2377399}]</code>.");'
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
return arr;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
```
</div>
</section>
## Solution
<section id='solution'>
```js
function orbitalPeriod(arr) {
var GM = 398600.4418;
var earthRadius = 6367.4447;
var 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))
};
});
}
orbitalPeriod([{name : "sputkin", avgAlt : 35873.5553}]);
```
</section>