You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Jason Godesky edited this page Jul 11, 2026
·
1 revision
isWithinRange returns true if the number n is within the defined range or false if it is outside of it.
Parameters
n: number
The number to test.
range: number[]
An array of numbers to define the range. The highest value in the array is the maximum and the lowest value is the minimum.
inclusive: boolean = true
Should this be an inclusive comparison (meaning that if n is equal to the minimum or maximum, it is counted as within range)? If set to false, then an exclusive comparison is applied instead (n must be strictly greater than the minimum and less than the maximum).
Default:true
Returns
true if n is within the range or false if it is not.
Examples
import{isWithinRange}from'@revolutionarygamesco/common'isWithinRange(0,[1,10])// falseisWithinRange(1,[1,10])// trueisWithinRange(1,[1,10],false)// false, because you asked for an exclusive comparisonisWithinRange(5,[1,10])// trueisWithinRange(5,[1,10])// true even when exclusiveisWithinRange(10,[1,10])// trueisWithinRange(10,[1,10],false)// false, because you asked for an exclusive comparisonisWithinRange(11,[1,10])// false