Created
March 31, 2019 11:26
-
-
Save kunukn/c350c9c7950f7a56271db2f9695b76f8 to your computer and use it in GitHub Desktop.
rangeMap
This file contains hidden or 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
| // map value x in range [a,b] to [c,d] | |
| function rangeMap(x, a, b, c, d) { | |
| if (a === b) return c; | |
| if (c === d) return c; | |
| return (x - a) / (b - a) * (d - c) + c; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment