← Back to challenges

Re-Map a Number from One Range to Another

JavaScriptHardalgorithmsmathnumbers

Instructions

Create a function similar to Processing's "map" function, in which a value and its range is taken and remapped to a new range.

The function takes 5 numbers:

  • Value: value
  • Range: low1 and high1
  • Range: low2 and high2

Examples

remap(7, 2, 12, 0, 100) ➞ 50

remap(17, 5, 55, 100, 30) ➞ 83.2

remap(50, 1, 51, 0, 100) ➞ 98

Notes

  • Test input will always be numbers.
  • If the input range is 0, return 0.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.