range

Checks if the given range is empty.

Type signature

([min, max]: [number, number]) => boolean

Examples

empty([2, 2]);
// ⇒ true
Try in REPL
empty([1, 5]);
// ⇒ false
Try in REPL

Questions

  • How to check if a given range is empty (0-length)?

TypeScript sourceJavaScript source

Checks if the given ranges are equal.

Type signature

([a, b]: [number, number], [c, d]: [number, number]) => boolean

Examples

equals([1, 2], [1, 2]);
// ⇒ true
Try in REPL
equals([4, 3], [1, 2]);
// ⇒ false
Try in REPL

Questions

  • How to check if two ranges are equal?

TypeScript sourceJavaScript source

Computes the signed length of the given range.

Type signature

([min, max]: [number, number]) => number

Examples

length([3, 15]);
// ⇒ 12
Try in REPL
length([1, 0]);
// ⇒ -1
Try in REPL

Questions

  • How to compute a signed length of a range?

TypeScript sourceJavaScript source

Splits the given range into subranges by excluding the given used ranged.

Type signature

(used: [number, number][], sourceRange?: number[]) => (range: [number, number]) => [number, number][];
export default split

Examples

split([
  [2, 3],
  [5, 7],
]);
// ⇒ [[0, 2], [3, 5], [7, 10]]
Try in REPL

Questions

  • How to split a range into subranges?

TypeScript sourceJavaScript source