Files
30-seconds-of-code/snippets/map-num-range.md
2023-04-28 22:29:23 +03:00

420 B

title, type, tags, cover, dateModified
title type tags cover dateModified
Map number to range snippet
math
clutter 2020-10-21T21:54:53+03:00

Maps a number from one range to another range.

  • Return num mapped between outMin-outMax from inMin-inMax.
const mapNumRange = (num, inMin, inMax, outMin, outMax) =>
  ((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
mapNumRange(5, 0, 10, 0, 100); // 50