Skip to content

Checks if a given number is within a given range and returns boolean

License

Notifications You must be signed in to change notification settings

writetome51/in-range

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

inRange(
      [min, max],
      num
): boolean

Checks if num is within range of [min, max].
min,max, and num must all be type "number".

Examples:

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

import { inRange} from '@writetome51/in-range';

About

Checks if a given number is within a given range and returns boolean

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published