map-range
Convert a function that has a domain and range of 0..1
to one with an arbitrary domain and range through application of a linear mapping.
That's a complicated way of saying this:
x |
fn(x) |
map(fn, 0, 1, 200, 300)(x) |
---|---|---|
0 | 0 | 200 |
0.25 | 0.25 | 225 |
0.5 | 0.5 | 250 |
0.75 | 0.75 | 275 |
1 | 1 | 300 |
Installation
$ npm install map-range
Usage
var map = ; { return x;} var mapped = ; ; // => 1050
API
map(fn, inStart, inEnd, outStart, outEnd)
fn
should be a single-arg function that expects values in the range 0..1 and returns a corresponding value in the same range. map
will wrap this function to accept arguments in the domain inStart..inEnd
and map, linearly, its output to the range outStart..outEnd
.
map(fn, outStart, outEnd)
As above but with implied values of 0 and 1 for inStart
, inEnd
.