Skip to content

Instantly share code, notes, and snippets.

View cesarfreites's full-sized avatar

César M. Freites cesarfreites

  • Venezuela
  • 16:57 (UTC -04:00)
View GitHub Profile
@cesarfreites
cesarfreites / rule-of-three.math.ts
Created July 15, 2025 07:58
Simple utility function that implements the mathematical rule of three.
/**
* Calculates a value using the rule of three principle.
* The logic is: "If 'baseCondition' results in 'baseResult', then 'targetCondition' will result in...?"
* Formula: (baseResult * targetCondition) / baseCondition
*
* @param baseCondition The base value for the proportion (A).
* @param baseResult The result corresponding to the base value (B).
* @param targetCondition The value for which to find the proportional result (C).
* @returns The calculated result (X), or null if any input is not a number or if division by zero occurs.
*/