Map number to range

JavaScript, Math · Oct 21, 2020

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

More like this

  • Sum of powers in range

    Calculates the sum of the powers of all the numbers from start to end (both inclusive).

    JavaScript, Math · Oct 22, 2020

  • Random number in range

    Generates a random number in the specified range.

    JavaScript, Math · Oct 22, 2020

  • Number in range

    Checks if the given number falls within the given range.

    JavaScript, Math · Nov 1, 2020