Created
May 24, 2016 03:40
-
-
Save nowri/d6787fab63c68944509536233b9dd751 to your computer and use it in GitHub Desktop.
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
const NumberUtil = (function() { | |
"use strict"; | |
function normalize(value, minimum, maximum) { | |
return (value - minimum) / (maximum - minimum); | |
} | |
function interpolate(normValue, minimum, maximum) { | |
return minimum + (maximum - minimum) * normValue; | |
} | |
function map(value, min1, max1, min2, max2) { | |
return interpolate(normalize(value, min1, max1), min2, max2); | |
} | |
return { | |
map, | |
normalize, | |
interpolate | |
}; | |
})(); | |
export default NumberUtil; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment