| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | --- | 
					
						
							|  |  |  | id: af4afb223120f7348cdfc9fd | 
					
						
							|  |  |  | title: Map the Debris | 
					
						
							|  |  |  | challengeType: 5 | 
					
						
							| 
									
										
										
										
											2019-07-31 11:32:23 -07:00
										 |  |  | forumTopicId: 16021 | 
					
						
							| 
									
										
										
										
											2021-01-13 03:31:00 +01:00
										 |  |  | dashedName: map-the-debris | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | # --description--
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | Return a new array that transforms the elements' average altitude into their orbital periods (in seconds). | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | The array will contain objects in the format `{name: 'name', avgAlt: avgAlt}`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | You can read about orbital periods [on Wikipedia](http://en.wikipedia.org/wiki/Orbital_period). | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | The values should be rounded to the nearest whole number. The body being orbited is Earth. | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 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>. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | # --hints--
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | `orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}])` should return `[{name: "sputnik", orbitalPeriod: 86400}]`. | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | ```js | 
					
						
							|  |  |  | assert.deepEqual(orbitalPeriod([{ name: 'sputnik', avgAlt: 35873.5553 }]), [ | 
					
						
							|  |  |  |   { name: 'sputnik', orbitalPeriod: 86400 } | 
					
						
							|  |  |  | ]); | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | `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}]`. | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | ```js | 
					
						
							|  |  |  | 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 } | 
					
						
							|  |  |  |   ] | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | # --seed--
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | ## --seed-contents--
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | function orbitalPeriod(arr) { | 
					
						
							|  |  |  |   var GM = 398600.4418; | 
					
						
							|  |  |  |   var earthRadius = 6367.4447; | 
					
						
							|  |  |  |   return arr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]); | 
					
						
							|  |  |  | ``` | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-27 19:02:05 +01:00
										 |  |  | # --solutions--
 | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | ```js | 
					
						
							|  |  |  | function orbitalPeriod(arr) { | 
					
						
							|  |  |  |   var GM = 398600.4418; | 
					
						
							|  |  |  |   var earthRadius = 6367.4447; | 
					
						
							| 
									
										
										
										
											2018-10-08 01:01:53 +01:00
										 |  |  |   var TAU = 2 * Math.PI; | 
					
						
							| 
									
										
										
										
											2018-09-30 23:01:58 +01:00
										 |  |  |   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}]); | 
					
						
							|  |  |  | ``` |