Files
30-seconds-of-code/snippets/mapNumRange.md
Angelos Chalaris 8a6b73bd0c Update covers
2023-02-16 22:24:28 +02:00

440 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Map number to range math clutter 2019-02-23T12:38:16+02:00 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