Created
March 25, 2017 16:20
-
-
Save rijkvanzanten/b4c3cb33b3bbb21e9755c54ec0269bf7 to your computer and use it in GitHub Desktop.
Convert number from one range to another
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
/** | |
* Convert value from one range to another | |
* @param {Number} value value to convert | |
* @param {Object} oldRange min, max of values range | |
* @param {Object} newRange min, max of desired range | |
* @return {Number} value converted to other range | |
*/ | |
function convertRange(value, oldRange, newRange) { | |
return ((value - oldRange.min) * (newRange.max - newRange.min)) / (oldRange.max - oldRange.min) + newRange.min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment