In other programming languages such as processing, there is a function which allows you to convert a number that falls within a range of numbers into a number within a diffe
I've taken August Miller's idea and added limits to them (value can't go outside the range of in_min and in_max and if it does it returns out_min and out_max respectively) and minified it for those who want a copy paste function for their scripts:
function map(n,i,o,r,t){return i>o?i>n?(n-i)*(t-r)/(o-i)+r:r:o>i?o>n?(n-i)*(t-r)/(o-i)+r:t:void 0}
params are like map(value, in_min, in_max, out_in, out_max)