13
mapNumRange.md
Normal file
13
mapNumRange.md
Normal file
@ -0,0 +1,13 @@
|
||||
### mapNumRange
|
||||
|
||||
Maps a number from one range to another range.
|
||||
|
||||
Returns `num` mapped between `outMin`-`outMax` from `inMin`-`inMax`.
|
||||
|
||||
```js
|
||||
const distance = (num, inMin, inMax, outMin, outMax) => (num - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
|
||||
```
|
||||
|
||||
```js
|
||||
mapNumRange(5,0,10,0,100); // 50
|
||||
```
|
||||
9
mapNumRange.test.js
Normal file
9
mapNumRange.test.js
Normal file
@ -0,0 +1,9 @@
|
||||
const expect = require('expect');
|
||||
const {mapNumRange} = require('./_30s.js');
|
||||
|
||||
test('mapNumRange is a Function', () => {
|
||||
expect(mapNumRange).toBeInstanceOf(Function);
|
||||
});
|
||||
test('Maps 5 to the range 0-100 from 0-10', () => {
|
||||
expect(distance(5,0,10,0,100)).toEqual(50);
|
||||
});
|
||||
@ -179,6 +179,7 @@ longestItem:array,string,utility,intermediate
|
||||
lowercaseKeys:object,intermediate
|
||||
luhnCheck:math,utility,advanced
|
||||
mapKeys:object,function,intermediate
|
||||
mapNumRange:math,beginner
|
||||
mapObject:array,object,advanced
|
||||
mapString:string,array,function,utility,beginner
|
||||
mapValues:object,function,intermediate
|
||||
|
||||
Reference in New Issue
Block a user