Remap Values


(Last modified: )
/**
 * Maps a number from one set range, to another set range.
 * @param {number} value The number to input.
 * @param {number} valueMin The lower bounds of the input.
 * @param {number} valueMax The upper bounds of the input.
 * @param {number} min The lower bounds of the output.
 * @param {number} max The upper bounds of the output.
 * @return {number} The new value mapped to the output range.
 */
function mapValue (value, valueMin, valueMax, min = 0, max = 1) {
    return (((value - valueMin) / (valueMax - valueMin)) * (max - min)) + min
}