
Mohammad A. answered 02/15/20
Tutor
5.0
(126)
Senior Javascript professional with 11+ years of experience
This is called Interpolation. In order to interpolate values from on scale to another, use the function below:
function lerp (inputValue, startRange, endRange){
return (1-inputValue)*startRange+inputValue*endRange;
}
You can then use for a range 100 - 500 as:
const output = lerg(0.1, 100, 500); // returns 140
output = lerg(0.3, 100, 500); // returns 220
output = lerg(0.6, 100, 500); // returns 340
output = lerg(0.9, 100, 500); // returns 460
output = lerg(1, 100, 500); // returns 500
Please let me know if you have any issue using it.