Maps a number from one range to another range.

Returns num mapped between outMinoutMax from inMininMax.

代码片段

const mapNumRange = (num, inMin, inMax, outMin, outMax) =>
  ((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;

使用样例

mapNumRange(5, 0, 10, 0, 100); // 50