Standardize settings file naming and relocate documentation files Fix code quality violations from rsx:check Reorganize user_management directory into logical subdirectories Move Quill Bundle to core and align with Tom Select pattern Simplify Site Settings page to focus on core site information Complete Phase 5: Multi-tenant authentication with login flow and site selection Add route query parameter rule and synchronize filename validation logic Fix critical bug in UpdateNpmCommand causing missing JavaScript stubs Implement filename convention rule and resolve VS Code auto-rename conflict Implement js-sanitizer RPC server to eliminate 900+ Node.js process spawns Implement RPC server architecture for JavaScript parsing WIP: Add RPC server infrastructure for JS parsing (partial implementation) Update jqhtml terminology from destroy to stop, fix datagrid DOM preservation Add JQHTML-CLASS-01 rule and fix redundant class names Improve code quality rules and resolve violations Remove legacy fatal error format in favor of unified 'fatal' error type Filter internal keys from window.rsxapp output Update button styling and comprehensive form/modal documentation Add conditional fly-in animation for modals Fix non-deterministic bundle compilation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
25 lines
869 B
JavaScript
25 lines
869 B
JavaScript
/*
|
|
Given the ratio a : b : c = 2 : 3 : 4
|
|
What is c, given a = 40?
|
|
|
|
A general ratio chain is a_1 : a_2 : a_3 : ... : a_n = r_1 : r2 : r_3 : ... : r_n.
|
|
Now each term can be expressed as a_i = r_i * x for some unknown proportional constant x.
|
|
If a_k is known it follows that x = a_k / r_k. Substituting x into the first equation yields
|
|
a_i = r_i / r_k * a_k.
|
|
|
|
Given an array r and a given value a_k, the following function calculates all a_i:
|
|
*/
|
|
|
|
function calculateRatios(r, a_k, k) {
|
|
const x = Fraction(a_k).div(r[k]);
|
|
return r.map(r_i => x.mul(r_i));
|
|
}
|
|
|
|
// Example usage:
|
|
const r = [2, 3, 4]; // Ratio array representing a : b : c = 2 : 3 : 4
|
|
const a_k = 40; // Given value of a (corresponding to r[0])
|
|
const k = 0; // Index of the known value (a corresponds to r[0])
|
|
|
|
const result = calculateRatios(r, a_k, k);
|
|
console.log(result); // Output: [40, 60, 80]
|