The starting value.
The ending value.
The value to calculate the inverse lerp factor for.
The inverse lerp factor, a value in the range [0, 1], indicating where value falls between start and end.
start and end are equal, the function returns 0.value is less than start, the factor is less than 0, indicating it's before start.value is greater than end, the factor is greater than 1, indicating it's after end.value is between start and end, the factor is between 0 and 1, indicating where value is along that range.// Calculate the inverse lerp factor for a value between two points.
const startValue = 10;
const endValue = 20;
const targetValue = 15; // The value we want to find the factor for.
const result = inverseLerp(startValue, endValue, targetValue);
// result is 0.5, indicating that targetValue is halfway between startValue and endValue.
// Handle the case where start and end are equal.
const equalStartAndEnd = 5;
const result2 = inverseLerp(equalStartAndEnd, equalStartAndEnd, equalStartAndEnd);
// result2 is 0, as start and end are equal.
Calculates the inverse linear interpolation (inverse lerp) factor based on a value between two numbers. The inverse lerp factor indicates where the given
valuefalls betweenstartandend.If
valueis equal tostart, the function returns 0. Ifvalueis equal toend, the function returns 1.