mergeIntervalsUnix
Signature
Section titled “Signature”mergeIntervalsUnix(intervals: { start: string | number; end: string | number; }[]): { start: number; end: number; }[]import { mergeIntervalsUnix } from "@northguild/gmt/unix/interval";Collapse a list of Unix epoch intervals into the minimum set of non-overlapping intervals.
- List-form generalization of
intervalUnionUnix, which is pairwise only. - Intervals are merged when they overlap or share an endpoint exactly (adjacent intervals ARE merged).
- Order of the input list does not matter; the result is sorted by start.
- Returns
[]for an empty list. - Returns
[]whenintervalsis not an array, when any element is not a{ start, end }record of finite numeric (or numeric-string) values, or when any element hasstart > end.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals |
{ start: string | number; end: string | number; }[] |
array of { start, end } records |
Returns
Section titled “Returns”the minimum set of non-overlapping { start, end } records, sorted by start, or [] on invalid input
Examples
Section titled “Examples”mergeIntervalsUnix([{ start: 0, end: 1000000 }, { start: 500000, end: 1500000 }]) // [{ start: 0, end: 1500000 }]mergeIntervalsUnix([]) // []