Skip to content

Instantly share code, notes, and snippets.

@ff6347
Forked from AugustMiller/map.js
Last active September 17, 2015 10:10
Show Gist options
  • Select an option

  • Save ff6347/93ab4fb1f36bec176feb to your computer and use it in GitHub Desktop.

Select an option

Save ff6347/93ab4fb1f36bec176feb to your computer and use it in GitHub Desktop.
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment