Created
October 4, 2022 22:15
-
-
Save aibolik/09c320e03bc7dcfecf132da671a034dd to your computer and use it in GitHub Desktop.
Map a number from input range to an output range
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* It maps a number `num` from original `[in_min, in_max]` range | |
* to output range `[out_min, out_max]`. | |
*/ | |
function mapRange(num, in_min, in_max, out_min, out_max) { | |
return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment