ratio()
- Import from
@gabreusi/hyrax- Examples
- Run, answers asserted
ts
function ratio(
value: number,
max?: number,
min?: number
): number;Defined in: core/number.ts:77
Where value sits inside the range [min, max], as a fraction: 0 at min, 1 at max. It is meant to be multiplied by other values to keep proportions. It does not clamp, so the result can be negative or above 1. An empty range (max === min) gives 0.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
value | number | undefined | The value to locate. |
max | number | 100 | The upper end of the range. |
min | number | 0 | The lower end of the range. |
Returns
number
The fraction of the range that value represents.
Example
ts
ratio(50); // => 0.5
ratio(30, 60); // => 0.5
ratio(75, 100, 50); // => 0.5