Skip to content

Instantly share code, notes, and snippets.

@aibolik
Created October 4, 2022 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aibolik/09c320e03bc7dcfecf132da671a034dd to your computer and use it in GitHub Desktop.
Save aibolik/09c320e03bc7dcfecf132da671a034dd to your computer and use it in GitHub Desktop.
Map a number from input range to an output range
/**
* 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