Skip to content

Instantly share code, notes, and snippets.

@alpual
Created February 4, 2019 20:31
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 alpual/7e6e2601b1a14532e78e1f85dba4fe88 to your computer and use it in GitHub Desktop.
Save alpual/7e6e2601b1a14532e78e1f85dba4fe88 to your computer and use it in GitHub Desktop.
Mapping values from one range to another range.
// function to map a value from one range to another range
const map = (value, in_min, in_max, out_min, out_max) => {
return (
((value - 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