fabianmoronzirfas
9/17/2015 - 10:10 AM

Extension of the native Number class to map a number in one range to a number in another.

Extension of the native Number class to map a number in one range to a number in another.

Number.prototype.map = function ( in_min , in_max , out_min , out_max ) {
  return ( this - in_min ) * ( out_max - out_min ) / ( in_max - in_min ) + out_min;
}