Skip to content

Instantly share code, notes, and snippets.

@nowri
Created May 24, 2016 03:40
Show Gist options
  • Save nowri/d6787fab63c68944509536233b9dd751 to your computer and use it in GitHub Desktop.
Save nowri/d6787fab63c68944509536233b9dd751 to your computer and use it in GitHub Desktop.
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