Skip to content

inRange

Verifies number within range, inclusive start, exclusive end, flexible order, defaulting to 0 if end unspecified

185 bytes

Basic usage

Pass the number, the start and the end (optional) of the range. The _.inRange function will return true if the given number is in the range.

  • The start is inclusive, the end is exclusive. So 10 is in the range 0-11 and 10-20, but not 0-10.
  • If an end is unspecified, the range defaults to >= 0 and < start.
  • If the end is lower than the start, the range is reversed.
import * as _ from 'radashi'
_.inRange(10, 0, 20) // true
_.inRange(9.99, 0, 10) // true
_.inRange(Math.PI, 0, 3.15) // true
_.inRange(10, 10, 20) // true
_.inRange(10, 0, 10) // false
_.inRange(1, 2) // true
_.inRange(1, 0) // false