Map function

theory

The purpose of the map function is to change the range of a value (map it into a new one).
It sees the a value not as absolute as as relative to a range between to other numbers.

format: map(value, baseLower, baseHigher, targetLower, targetHigher)

function map(s, a1, a2, b1, b2) {return b1 + (s - a1) * (b2 - b1) / (a2 - a1)} // or ES6 let map = (s, a1, a2, b1, b2) => b1 + (s - a1) * (b2 - b1) / (a2 - a1)

example

map(10, 0, 20, 0, 100) // = 50

Reference

No known

History Mar 29, 2018