Files
30-seconds-of-code/map-number-range.md
2019-02-18 14:23:47 +00:00

329 B

mapNumRange

Maps a number range to another number range.

Returns a number mapped from the in range to the out range.

const mapNumRange = (num, in_min, in_max, out_min, out_max) => {
    return (num - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
  }
mapNumRange(5,0,10,0,100); // '50'