dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
1.7 KiB
1.7 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 68c1a929005bf54d342aa8d6 | Challenge 59: Space Week Day 5: Goldilocks Zone | 28 | challenge-59 |
--description--
For the fifth day of Space Week, you will calculate the "Goldilocks zone" of a star - the region around a star where conditions are "just right" for liquid water to exist.
Given the mass of a star, return an array with the start and end distances of its Goldilocks Zone in Astronomical Units.
To calculate the Goldilocks Zone:
- Find the luminosity of the star by raising its mass to the power of 3.5.
- The start of the zone is 0.95 times the square root of its luminosity.
- The end of the zone is 1.37 times the square root of its luminosity.
- Return the distances rounded to two decimal places.
For example, given 1 as a mass, return [0.95, 1.37].
--hints--
goldilocksZone(1) should return [0.95, 1.37].
assert.deepEqual(goldilocksZone(1), [0.95, 1.37]);
goldilocksZone(0.5) should return [0.28, 0.41].
assert.deepEqual(goldilocksZone(0.5), [0.28, 0.41]);
goldilocksZone(6) should return [21.85, 31.51].
assert.deepEqual(goldilocksZone(6), [21.85, 31.51]);
goldilocksZone(3.7) should return [9.38, 13.52].
assert.deepEqual(goldilocksZone(3.7), [9.38, 13.52]);
goldilocksZone(20) should return [179.69, 259.13].
assert.deepEqual(goldilocksZone(20), [179.69, 259.13]);
--seed--
--seed-contents--
function goldilocksZone(mass) {
return mass;
}
--solutions--
function goldilocksZone(mass) {
const luminosity = Math.pow(mass, 3.5);
const start = 0.95 * Math.sqrt(luminosity);
const end = 1.37 * Math.sqrt(luminosity);
return [Number(start.toFixed(2)), Number(end.toFixed(2))];
}