Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

map values js

function mapValues(value, oldRange, newRange) {
    var newValue = (value - oldRange[0]) * (newRange[1] - newRange[0]) / (oldRange[1] - oldRange[0]) + newRange[0];
    return Math.min(Math.max(newValue, newRange[0]) , newRange[1]);
}
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #map #values #js
ADD COMMENT
Topic
Name
2+3 =