Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Humpty Dumpty Form by SaintDron
"use strict";
function spheroid(height, width) {
const getE = (a, c) => Math.sqrt(1 - a ** 2 / c ** 2),
a = width / 2, c = height / 2;
let volume = Math.PI / 6 * width ** 2 * height,
area = 2 * Math.PI * a ** 2,
e;
if (c < a) { // oblate
e = getE(c, a);
area += Math.PI * c ** 2 / e * Math.log((1 + e) / (1 - e));
} else if (c > a) { // prolate
e = getE(a, c);
area *= 1 + c / (a * e) * Math.asin(e);
} else { // sphere
area *= 2;
}
return [+volume.toFixed(2), +area.toFixed(2)];
}
var assert = require('assert');
if (!global.is_checking) {
// These "asserts" are used for self-checking and not for an auto-testing
assert.deepEqual(spheroid(4, 2), [8.38, 21.48])
assert.deepEqual(spheroid(2, 2), [4.19, 12.57])
assert.deepEqual(spheroid(2, 4), [16.76, 34.69])
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Aug. 15, 2018