https://github.com/writetome51/in-range
Checks if a given number is within a given range and returns boolean
https://github.com/writetome51/in-range
boolean check inrange number range
Last synced: 6 months ago
JSON representation
Checks if a given number is within a given range and returns boolean
- Host: GitHub
- URL: https://github.com/writetome51/in-range
- Owner: writetome51
- License: mit
- Created: 2018-10-14T22:12:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-24T18:40:43.000Z (almost 5 years ago)
- Last Synced: 2025-07-08T16:11:57.008Z (6 months ago)
- Topics: boolean, check, inrange, number, range
- Language: JavaScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# inRange(
[min, max],
num
): boolean
Checks if `num` is within range of `[min, max]`.
`min`,`max`, and `num` must all be type "number".
## Examples:
```js
inRange([2.5, 8.5], 8.6); // --> false
inRange([0, 200], 100); // --> true
inRange([-10, 0], -10); // --> true
inRange([-10, 0], -11); // --> false
// The numbers cannot be strings, because this gives unpredictable results.
// For instance, in string comparison, '30' is greater than both '20' and '100'
inRange(['20', '100'], '30');
// 'Error: Input must be of type "number"'
```
## Installation
`npm i @writetome51/in-range`
## Loading
```js
import { inRange} from '@writetome51/in-range';
```