8000 [ADD] Map the debris added · luisprooc/js-algorithms@0bf834a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0bf834a

Browse files
committed
[ADD] Map the debris added
1 parent 2805c22 commit 0bf834a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,25 @@ spinalCase("Teletubbies say Eh-oh") should return the string teletubbies-say-eh-
764764

765765
spinalCase("AllThe-small Things") should return the string all-the-small-things.
766766

767+
```
768+
769+
770+
## Map the Debris
771+
772+
Return a new array that transforms the elements' average altitude into their orbital periods (in seconds).
773+
774+
The array will contain objects in the format {name: 'name', avgAlt: avgAlt}.
775+
776+
You can read about orbital periods on Wikipedia.
777+
778+
The values should be rounded to the nearest whole number. The body being orbited is Earth.
779+
780+
The radius of the earth is 6367.4447 kilometers, and the GM value of earth is 398600.4418 km3s-2.
781+
782+
783+
```javascript
784+
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]) should return [{name: "sputnik", orbitalPeriod: 86400}].
785+
786+
orbitalPeriod([{name: "iss", avgAlt: 413.6}, {name: "hubble", avgAlt: 556.7}, {name: "moon", avgAlt: 378632.553}]) should return [{name : "iss", orbitalPeriod: 5557}, {name: "hubble", orbitalPeriod: 5734}, {name: "moon", orbitalPeriod: 2377399}].
787+
767788
```

src/mapDebris.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function orbitalPeriod(arr) {
2+
var GM = 398600.4418;
3+
var earthRadius = 6367.4447;
4+
const a = 2 * Math.PI;
5+
let newArr = arr.map(item => {
6+
return {name: item.name, orbitalPeriod: Math.round(Math.sqrt(Math.pow(earthRadius + item.avgAlt,3)/GM) * a)}
7+
});
8+
return newArr;
9+
}
10+
11+
console.log(orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]));

0 commit comments

Comments
 (0)
0