Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
36 lines (23 loc) · 1.6 KB

File metadata and controls

36 lines (23 loc) · 1.6 KB
Copy raw file
Download raw file
Outline
Edit and raw actions

map

Convert a value in one number range to a value in another number range.

Math.map(0, 0, 0, 0, 0)

A map is a conversion of one span of numbers to another. If a dog can live to 16 years and a person lives to 87 years, how do you make a 16 year life span seem like a 87 year life span? You say that one dog year is like some number of people years. This is a mapping of dog years to people years.

Fahrenheit and Celsius are different ways to measure temperature. Celsius doesn't use the same amount of degrees as Fahrenheit. So, there is more energy in one degree of Celsius. If you want to convert a temperature value of Fahrenheit (something between freezing and boiling maybe) to Celsius, you can use Math.map(50, 32, 212, 0, 100). The map makes 50 degrees of Fahrenheit turn into 10 degrees of Celsius.

Parameters

  • value: a number to convert from one range to another.
  • fromLow: the low number of the range to convert from.
  • fromHigh: the high number of the range to convert from
  • toLow: the low number of the range to convert to.
  • toHigh: the high number of the range to convert to.

Returns

  • a new value that is a number converted from original value using a mapping of the from range into the to range.

Example #example

Use a lifespan map to find out the age in "people years" of a dog that's 7 years old.

let dogsAge = 7 
let peoplesAge = Math.map(dogsAge, 1, 16, 15, 87) 

See also

constrain

Morty Proxy This is a proxified and sanitized view of the page, visit original site.