scrimba
Clean Code
Clean Variables: Magic Numbers 🧙
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Clean Variables: Magic Numbers 🧙
AboutCommentsNotes
Clean Variables: Magic Numbers 🧙
Expand for more info
index.js
run
preview
console
// Magic Numbers

function orbitalPeriod(arr) {
const a = 2 * Math.PI;
const newArr = [];

const getOrbPeriod = function(obj) {
const c = Math.pow(6367.447 + obj.avgAlt, 3);
const b = Math.sqrt(c / 398600.4418);
const orbPeriod = Math.round(a * b);
delete obj.avgAlt;
obj.orbitalPeriod = orbPeriod;

return obj;
}

for (elem in arr) {
newArr.push(getOrbPeriod(arr[elem]))
}

return newArr;
}
Console
/index.html
-3:44