Please tell me what you think about the use of class in this challenge and these kind of problems. Should it be reserved for more OOP kind of approaches?
My code
function orbitalPeriod(arr) {
let output=[];
var GM = 398600.4418;
var earthRadius = 6367.4447;
/* Pay attention below */
class SpaceThing {
constructor(name,alt) {
this.name = name;
this.orbitalPeriod=Math.round(
2*Math.PI*Math.sqrt(Math.pow(earthRadius+alt,3)/GM)
);
}
}
/* Pay attention above */
/* This builds the answer array */
for(let i=0;i<arr.length;i++) {
output.push(new SpaceThing(arr[i].name,arr[i].avgAlt))
}
return output;
}
orbitalPeriod([{name : "sputnik", avgAlt : 35873.5553}]);
Thanks for your interest.
Challenge: Map the Debris
Link to the challenge: