@yetnt/ump
Version:
A very useless math package for your complex javascript projects
35 lines • 936 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.dinRatio = void 0;
/**
* Divides `x` into the ratio of `y` : `z` and returns the resulting values as an array.
*
* @param x - The value to be divided.
* @param y - The ratio value for `y`.
* @param z - The ratio value for `z`.
* @param round - If set to true, will round of the value to 2 decimal places.
*
*/
function dinRatio(x, y, z, round) {
const a = y + z;
const ans = [];
let q = (y / a) * x;
if (/[.]/.test(q.toString())) {
q = round ? q.toFixed(2) : q.toString();
ans.push(q);
}
else {
ans.push(q.toString());
}
let w = (z / a) * x;
if (/[.]/.test(w.toString())) {
w = round ? w.toFixed(2) : w.toString();
ans.push(w);
}
else {
ans.push(w.toString());
}
return ans;
}
exports.dinRatio = dinRatio;
//# sourceMappingURL=DinRatio.js.map