Files
30-seconds-of-code/snippets/mapNumRange.md
Angelos Chalaris 611729214a Snippet format update
To match the starter (for the migration)
2019-08-13 10:29:12 +03:00

348 B

title, tags
title tags
mapNumRange math,beginner

Maps a number from one range to another range.

Returns 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